-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInput.js
111 lines (98 loc) · 2.65 KB
/
Input.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Created with JetBrains WebStorm.
* User: JasonOwnzBiatch
* Date: 7/07/13
* Time: 6:20 PM
* To change this template use File | Settings | File Templates.
*/
//MODULE IMPORTS
var Input = (function () {
"use strict"
//Constructor
var Input = function (s) {
source = s;
//scope of the current input object
var scope = this;
reset.call(this);
document.onkeydown = document.onkeyup = function (e) {
handleKey.call(scope, e);
};
};
//Public vars:
Input.prototype.curKeyType = 1;
Input.prototype.keys = new Array();
//Private vars:
var KEY_SIZE = 16;
var source = undefined;
var keyTypes = {
NORMAL: 1
};
//Private:
var reset = function reset() {
this.keys = new Array(KEY_SIZE);
for (var i = 0; i < KEY_SIZE; i++) {
this.keys[i] = 0;
}
};
//Public:
function handleKey(evt) {
var charCode = evt.which;
var charStr = String.fromCharCode(charCode);
var value = evt.type == 'keydown' ? 1 : 0;
//console.log("test!!: " + value + " keys " + this.keys);
switch (charStr) {
case '1':
this.keys[0x1] = value;
break;
case '2':
this.keys[0x2] = value;
break;
case '3':
this.keys[0x3] = value;
break;
case '4':
this.keys[0xC] = value;
break;
case 'Q':
this.keys[0x4] = value;
break;
case 'W':
this.keys[0x5] = value;
break;
case 'E':
this.keys[0x6] = value;
break;
case 'R':
this.keys[0xD] = value;
break;
case 'A':
this.keys[0x7] = value;
break;
case 'S':
this.keys[0x8] = value;
break;
case 'D':
this.keys[0x9] = value;
break;
case 'F':
this.keys[0xE] = value;
break;
case 'Z':
this.keys[0xA] = value;
break;
case 'X':
this.keys[0x0] = value;
break;
case 'C':
this.keys[0xB] = value;
break;
case 'V':
this.keys[0xF] = value;
break;
default:
//console.log("crap key found");
}
//keyPressed = value ? value : keyPressed;
};
return Input;
})();