libConsole/getch.c
changeset 49 77094ec383cf
child 52 1fa566e9d13f
equal deleted inserted replaced
48:b94d657a9acb 49:77094ec383cf
       
     1 #include <stdio.h>
       
     2 #include <jni.h>
       
     3 #include <Console.h>
       
     4 
       
     5 #ifdef WIN32
       
     6 #include <conio.h>
       
     7 
       
     8 int getch ()
       
     9 {
       
    10     int ch = -1;
       
    11 
       
    12     while (!kbhit ()) {
       
    13         ch =::getch ();
       
    14     }
       
    15 
       
    16     return ch;
       
    17 }
       
    18 
       
    19 #else
       
    20 #include <termios.h>
       
    21 
       
    22 int getch ()
       
    23 {
       
    24     int ch = -1, fd = 0;
       
    25     struct termios neu, alt;
       
    26 
       
    27     fd = fileno (stdin);
       
    28     tcgetattr (fd, &alt);
       
    29     neu = alt;
       
    30     neu.c_lflag &= ~(ICANON | ECHO);
       
    31     tcsetattr (fd, TCSANOW, &neu);
       
    32     ch = getchar ();
       
    33     tcsetattr (fd, TCSANOW, &alt);
       
    34     return ch;
       
    35 }
       
    36 #endif
       
    37 
       
    38 JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass)
       
    39 {
       
    40     return getch ();
       
    41 }