author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:50:39 +0200 | |
changeset 74 | 829976007e62 |
parent 69 | b5912e5f899f |
child 77 | 49e0babccb23 |
permissions | -rw-r--r-- |
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 |
|
69
b5912e5f899f
Useless cross_getch hack removed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
53
diff
changeset
|
12 |
ch = getch (); |
53
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
return ch; |
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 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
17 |
#else |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
18 |
#include <termios.h> |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
int cross_getch () |
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 ch = -1, fd = 0; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
struct termios neu, alt; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
25 |
fd = fileno (stdin); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
tcgetattr (fd, &alt); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
neu = alt; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
neu.c_lflag &= ~(ICANON | ECHO); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
tcsetattr (fd, TCSANOW, &neu); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
ch = getchar (); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
tcsetattr (fd, TCSANOW, &alt); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
return ch; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
} |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
#endif |
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 |
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
|
37 |
{ |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
return cross_getch (); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
} |