Menu

[r1]: / src / InputProxy.java  Maximize  Restore  History

Download this file

67 lines (51 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//by Christophe ILLY 2017
//under MIT license
public class InputProxy {
static {
System.loadLibrary("inputNative");
}
public static InputProxy in = new InputProxy();
//event types
public static int KEY_PRESSED = 0;
public static int KEY_RELEASED = 1;
//keys (windows values)
public static int SCAN_CODE_ECHAP = 1;
public static int SCAN_CODE_SPACE = 57;
public static int SCAN_CODE_ARROW_LEFT = 75;
public static int SCAN_CODE_ARROW_RIGHT = 77;
public static int SCAN_CODE_ARROW_UP = 72;
public static int SCAN_CODE_ARROW_DOWN = 80;
public static int SCAN_CODE_A = 16;
public static int SCAN_CODE_Q = 30;
//... add whatever you need
public InputProxy() {
if(!init()){
System.out.println(getErrorMsg());
exit();
}
}
private native boolean init();
public native void exit();
public native String getErrorMsg();
public native String eventToString();
public native boolean checkEvents();
public native int getEvent();
public native int getEventType();
public static void main(String[] args) {
System.out.println("(Quit : Q)");
boolean run = true;
while(run){
if(InputProxy.in.checkEvents()){
int event = InputProxy.in.getEvent();
System.out.println(event);
System.out.println(InputProxy.in.eventToString());
if(event == SCAN_CODE_Q){
run = false;
}
}
try{ Thread.sleep(1); } catch(InterruptedException e) {}
}
InputProxy.in.exit();
System.out.println("Goodbye.");
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.