-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeypress.js
58 lines (35 loc) · 785 Bytes
/
keypress.js
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
var BUTTON_LEFT = 0;
var BUTTON_RIGHT = 0;
var left_strcode = "z";
var right_strcode = "c";
function KeyCodeToString(e) {
var keynum;
if(e.keyCode) {
keynum = e.keyCode;
}
else if(e.which){
keynum = e.which;
}
else {
console.log("ERROR, keypress");
}
return String.fromCharCode(keynum);
}
function KeyUp_Handler(e){
var key_str = KeyCodeToString(e);
console.log("up" + key_str);
if(key_str == left_strcode)
BUTTON_LEFT = 0;
if(key_str == right_strcode)
BUTTON_RIGHT = 0;
}
function KeyDown_Handler(e){
var key_str = KeyCodeToString(e);
console.log("down" + key_str);
if(key_str == left_strcode) {
BUTTON_LEFT = 1;
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}
if(key_str == right_strcode)
BUTTON_RIGHT = 1;
}