-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
48 lines (45 loc) · 884 Bytes
/
test.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
var Keyboard = require('./keyboard').Keyboard
var window = {}
var k1 = Keyboard()
var k2 = new Keyboard()
console.log(k1)
console.log(k2)
console.log(k2 === k1)
var keyboard = new Keyboard()
var event = {
stopImmediatePropagation: function () { },
preventDefault: function () { },
stopPropagation: function () { }
}
function keydown(key) {
event.key = key
event.type = 'keydown'
keyboard.__keydown(event)
}
function keyup(key) {
event.key = key
event.type = 'keyup'
keyboard.__keyup(event)
}
keyboard.register('uk', function () {
console.log('test uk successfully.')
}, ["Shift", "b"], ["Shift", "e"])
keydown('Shift')
keydown('e')
keyup('e')
keyup('Shift')
// > hhhhh
keydown('Shift')
keydown('b')
keyup('b')
keyup('Shift')
// > hhhhh
keydown('Shift')
keydown('e')
keyup('e')
keyup('Shift')
// > hhhhh
// output:
// hhhhh
// hhhhh
// hhhhh