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
|
define.class('$system/base/keyboard', function (require, exports){
this.toKey = {
8:'backspace',
259:'backspace',9:'tab',
257:'enter',
13:'enter',340:'shift',344:'shift',341:'ctrl',345:'ctrl',342:'alt',346:'alt',
19:'pause',20:'caps',27:'escape',
32:'space',266:'pgup',267:'pgdn',
269:'end',268:'home',263:'leftarrow',265:'uparrow',262:'rightarrow',264:'downarrow',
45:'insert',261:'delete',
48:'num0',49:'num1',50:'num2',51:'num3',52:'num4',
53:'num5',54:'num6',55:'num7',56:'num8',57:'num9',
65:'a',66:'b',67:'c',68:'d',69:'e',70:'f',71:'g',
72:'h',73:'i',74:'j',75:'k',76:'l',77:'m',78:'n',
79:'o',80:'p',81:'q',82:'r',83:'s',84:'t',85:'u',
86:'v',87:'w',88:'x',89:'y',90:'z',
343:'leftmeta',348:'rightmeta',
96:'pad0',97:'pad1',98:'pad2',99:'pad3',100:'pad4',101:'pad5',
102:'pad6',103:'pad7',104:'pad8',105:'pad9',
106:'multiply',107:'add',109:'subtract',110:'decimal',111:'divide',
290:'f1',291:'f2',292:'f3',293:'f4',294:'f5',295:'f6',
296:'f7',297:'f8',298:'f9',299:'f10',300:'f11',301:'f12',
144:'numlock',145:'scrollock',186:'semicolon',187:'equals',188:'comma',
189:'dash',190:'period',191:'slash',192:'accent',219:'openbracket',
220:'backslash',221:'closebracket',222:'singlequote',
}
this.toCode = {}
for(var k in this.toKey){
var key = this.toKey[ k ]
this.toCode[key] = k
if(!this.isAttribute(key))
this.defineAttribute(key, Config({type:int}))
}
this.textareaFocus = function(){
}
this.textAreaRespondToMouse = function(){
}
this.checkSpecialKeys = function(){
}
this.atConstructor = function(device){
var document = device.document
document.addEventListener('keydown', function(e){
var code = e.which>255?e.which:e.keyCode
var keyname = this.toKey[ code ]
if( keyname ) this[keyname] = 1
var msg = {
repeat: e.repeat,
code: code,
name: keyname
}
msg[msg.name] = 1
this.emit('down', msg)
}.bind(this))
document.addEventListener('keypress', function(e){
})
document.addEventListener('keyup', function(e){
var code = e.which>255?e.which:e.keyCode
var keyname = this.toKey[ code ]
if( keyname ) this[keyname] = 0
var msg = {
repeat: e.repeat,
code: code,
name: keyname
}
msg[msg.name] = 1
this.emit('up', msg)
}.bind(this))
}
})
|