libConsole/getch.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 51 a03372ef9714
parent 49 77094ec383cf
child 52 1fa566e9d13f
permissions -rw-r--r--
base10.c added and set_limit changed * base10: Divides a value into a power of 10 * set_limit: parameter changed to MB Values. committer: Markus Bröker <mbroeker@largo.homelinux.org>

#include <stdio.h>
#include <jni.h>
#include <Console.h>

#ifdef WIN32
#include <conio.h>

int getch ()
{
    int ch = -1;

    while (!kbhit ()) {
        ch =::getch ();
    }

    return ch;
}

#else
#include <termios.h>

int getch ()
{
    int ch = -1, fd = 0;
    struct termios neu, alt;

    fd = fileno (stdin);
    tcgetattr (fd, &alt);
    neu = alt;
    neu.c_lflag &= ~(ICANON | ECHO);
    tcsetattr (fd, TCSANOW, &neu);
    ch = getchar ();
    tcsetattr (fd, TCSANOW, &alt);
    return ch;
}
#endif

JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass)
{
    return getch ();
}