libConsole/cross_getch.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 16 Apr 2009 12:49:12 +0200
changeset 53 6b3d7e3418c1
child 69 b5912e5f899f
permissions -rw-r--r--
getch.c renamed to cross_getch.c committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
#include <stdio.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
#include <jni.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
#include <Console.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
#ifdef WIN32
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <conio.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
int cross_getch ()
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    10
    int ch = -1;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    11
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
    while (!kbhit ()) {
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
        ch = getch ();
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    14
    }
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    16
    return ch;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
}
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    19
#else
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
#include <termios.h>
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    21
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
int cross_getch ()
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    24
    int ch = -1, fd = 0;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
    struct termios neu, alt;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    26
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
    fd = fileno (stdin);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
    tcgetattr (fd, &alt);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    29
    neu = alt;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
    neu.c_lflag &= ~(ICANON | ECHO);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
    tcsetattr (fd, TCSANOW, &neu);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
    ch = getchar ();
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
    tcsetattr (fd, TCSANOW, &alt);
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    34
    return ch;
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
}
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    36
#endif
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    37
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
JNIEXPORT jint JNICALL Java_Console_getch (JNIEnv * env, jclass lass)
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
{
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
    return cross_getch ();
6b3d7e3418c1 getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    41
}