author | Markus Brökers <mbroeker@largo.homelinux.org> |
Wed, 18 Aug 2010 18:17:51 +0200 | |
changeset 143 | 88d9b8bfa7a5 |
parent 134 | 8325a0fc22cd |
permissions | -rw-r--r-- |
77 | 1 |
/** |
2 |
* libConsole/cross_getch.c |
|
3 |
* Copyright (C) 2008 Markus Broeker |
|
4 |
*/ |
|
5 |
||
53
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
6 |
#include <stdio.h> |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
7 |
#include <jni.h> |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <Console.h> |
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 |
#ifdef WIN32 |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
11 |
#include <conio.h> |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
|
134 | 13 |
static int cross_getch () |
53
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 |
int ch = -1; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
|
69
b5912e5f899f
Useless cross_getch hack removed
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
53
diff
changeset
|
17 |
ch = getch (); |
53
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 |
return ch; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
} |
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 |
#else |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
23 |
#include <termios.h> |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
|
93
66b3596f71b6
make cross_getch invisible
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
77
diff
changeset
|
25 |
static int cross_getch () |
53
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 |
int ch = -1, fd = 0; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
28 |
struct termios neu, alt; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
29 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
30 |
fd = fileno (stdin); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
31 |
tcgetattr (fd, &alt); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
neu = alt; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
33 |
neu.c_lflag &= ~(ICANON | ECHO); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
34 |
tcsetattr (fd, TCSANOW, &neu); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
ch = getchar (); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
36 |
tcsetattr (fd, TCSANOW, &alt); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
37 |
return ch; |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
38 |
} |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
39 |
#endif |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
|
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
41 |
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
|
42 |
{ |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
43 |
return cross_getch (); |
6b3d7e3418c1
getch.c renamed to cross_getch.c
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
44 |
} |