-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathkeyboard.js
50 lines (45 loc) · 1.19 KB
/
keyboard.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
var lastKey = -1;
window.addEventListener('keyup', function (e) {
if(e.keyCode === 90) {
Controls.handleFire();
}
else if(e.keyCode === 88) {
Controls.handleCharge();
}
else if(e.keyCode === 13) {
Controls.handlePause();
}
else if (e.keyCode === 37 && lastKey === 37)
Controls.handleLeftEnd();
else if (e.keyCode === 39 && lastKey === 39)
Controls.handleRightEnd();
});
window.addEventListener('keydown', function (e) {
if (e.keyCode === 37) {
Controls.handleLeft();
lastKey = e.keyCode;
}
else if (e.keyCode === 39) {
Controls.handleRight();
lastKey = e.keyCode;
}
});
// function keyAction(key) {
// document.querySelector("#result").append(key + " ");
// }
// var keyTimerMap = {};
// var keyDelay = 50;
// window.addEventListener('keydown', function(e) {
// if (!keyTimerMap[e.keyCode]) {
// keyTimerMap[e.keyCode] = setInterval(function() {
// keyAction(e.keyCode);
// }, keyDelay);
// }
// });
// window.addEventListener('keyup', function(e) {
// var timer = keyTimerMap[e.keyCode];
// if (timer) {
// clearInterval(timer);
// delete keyTimerMap[e.keyCode];
// }
// });