-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.js
66 lines (58 loc) · 1.63 KB
/
keyboard.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
normal = ["`1234567890-=".split(''),
"qwertyuiop[]\\".split(''),
"asdfghjkl;’".split(''),
"zxcvbnm,./".split('')
]
shift = ["~!@#$%^&*()_+".split(''),
"QWERTYUIOP{}|".split(''),
"ASDFGHJKL:\"".split(''),
"ZXCVBNM<>?".split('')
]
option = ["`¡™£¢∞§¶•ªº–≠".split(''),
"Œ∑´®†¥¨ˆøπ“‘«".split(''),
"Åß∂ƒ©˙∆˚¬…æ".split(''),
"Ω≈ç√∫˜µ≤≥÷".split('')
]
shiftOption = ["`⁄€‹›fifl‡°·‚—±".split(''),
"Œ„´‰ˇÁ¨ˆØ∏”’»".split(''),
"ÅÍÎÏ˝ÓÔÒÚÆ".split(''),
"¸˛Ç◊ı˜Â¯˘¿".split('')
]
STATE_NORMAL = 0
STATE_SHIFT = 0x1
STATE_OPTION = 0x2
STATE_SHIFT_OPTION = STATE_OPTION | STATE_SHIFT
state_chars_map = []
state_chars_map[STATE_NORMAL] = normal
state_chars_map[STATE_SHIFT] = shift
state_chars_map[STATE_SHIFT_OPTION] = shiftOption
state_chars_map[STATE_OPTION] = option
var vue = new Vue({
el: '#keyboard',
data: {
keyState: STATE_NORMAL,
chars: state_chars_map[STATE_NORMAL],
shiftKey: false,
optionKey: false
}
});
function update() {
vue.chars = state_chars_map[vue.keyState];
vue.shiftKey = vue.keyState & STATE_SHIFT
vue.optionKey = vue.keyState & STATE_OPTION
}
document.addEventListener('keyup', function(e) {
console.log(e);
if (e.key == 'Alt') {
vue.keyState ^= STATE_OPTION
clearInterval(timer)
} else if (e.key == 'Shift') {
vue.keyState ^= STATE_SHIFT
clearInterval(timer)
}
update()
})
timer = setInterval(function () {
vue.keyState = (vue.keyState + 1) % 0x4;
update()
}, 5000)