-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.js
More file actions
32 lines (26 loc) · 670 Bytes
/
Copy pathkeys.js
File metadata and controls
32 lines (26 loc) · 670 Bytes
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
// =================
// KEYBOARD HANDLING
// =================
var keys = [];
function handleKeydown(evt) {
keys[evt.keyCode] = true;
}
function handleKeyup(evt) {
keys[evt.keyCode] = false;
}
// Inspects, and then clears, a key's state
//
// This allows a keypress to be "one-shot" e.g. for toggles
// ..until the auto-repeat kicks in, that is.
//
function eatKey(keyCode) {
var isDown = keys[keyCode];
keys[keyCode] = false;
return isDown;
}
// A tiny little convenience function
function keyCode(keyChar) {
return keyChar.charCodeAt(0);
}
window.addEventListener("keydown", handleKeydown);
window.addEventListener("keyup", handleKeyup);