forked from FreekBes/bledom_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kbd.js
71 lines (60 loc) · 1.48 KB
/
kbd.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var keyDebug = false;
var keysPressed = [];
var onlyOneKey = false;
var useKbd = false;
window.addEventListener("keydown", function(e) {
if (e.target.type != 'text' && e.target.nodeName != 'TEXTAREA' && e.target.getAttribute("contenteditable") == null) {
var key = e.keyCode || e.which;
if (keyDebug === true) {
console.log("Keycode for KEYDOWN: " + key);
}
if (keysPressed.indexOf(key) == -1) {
keysPressed.push(key);
switch(key) {
case 65: // [A]
//setColor(255, 0, 0);
//brightness[0] = 255;
//keyPressed = true;
break;
case 83: // [S]
//setColor(0, 255, 0);
//brightness[1] = 255;
//keyPressed = true;
break;
case 68: // [D]
//setColor(0, 0, 255);
//brightness[2] = 255;
//keyPressed = true;
break;
case 116: // [F5]
window.location.reload();
break;
}
}
return false;
}
});
window.addEventListener("keyup", function(e) {
if (e.target.type != 'text' && e.target.nodeName != 'TEXTAREA' && e.target.getAttribute("contenteditable") == null) {
var key = e.keyCode || e.which;
if (keyDebug === true) {
console.log("Keycode for KEYUP: " + key);
}
keyPressed = false;
if (keysPressed.indexOf(key) > -1) {
keysPressed.splice(keysPressed.indexOf(key), 1);
switch(key) {
case 65: // [A]
//brightness[0] = 0;
break;
case 83: // [S]
//brightness[1] = 0;
break;
case 68: // [D]
//brightness[2] = 0;
break;
}
}
return false;
}
});