-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
88 lines (83 loc) · 1.87 KB
/
main.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
var contextId = -1;
var requestId = 0;
function sendEvent(key, isShift, isCtrl) {
if (isShift === undefined) {
isShift = false;
}
if (isCtrl == undefined) {
isCtrl = false;
}
const keyData = {
'type': 'keydown',
'altKey': false,
'ctrlKey': isCtrl,
'shiftKey': isShift,
'key': key,
'code': key,
'requestId': String(requestId)
};
chrome.input.ime.sendKeyEvents({ "contextID": contextId, "keyData": [keyData] });
}
chrome.input.ime.onFocus.addListener(function (context) {
contextId = context.contextID;
});
chrome.input.ime.onBlur.addListener(function (context) {
contextId = -1;
});
chrome.commands.onCommand.addListener(function (c) {
if (contextId == -1) {
return;
}
requestId += 1;
switch (c) {
case "00-up":
sendEvent('ArrowUp');
break;
case "01-down":
sendEvent('ArrowDown');
break;
case "02-left":
sendEvent('ArrowLeft');
break;
case "03-right":
sendEvent('ArrowRight');
break;
case "10-home":
sendEvent('Home');
break;
case "11-end":
sendEvent('End');
break;
case "20-delete":
sendEvent('Delete');
break;
case "30-backspace":
sendEvent('Backspace');
break;
case "40-enter":
sendEvent('Enter');
break;
case "50-killend":
sendEvent('End', true);
sendEvent('KeyX', false, true);
break;
case "60-cut":
sendEvent('KeyX', false, true);
break;
case "61-paste":
sendEvent('KeyV', false, true);
break;
case "90-original-ctrl-f":
sendEvent('KeyF', false, true);
break;
case "91-original-ctrl-a":
sendEvent('KeyA', false, true);
break;
case "92-original-ctrl-p":
sendEvent('KeyP', false, true);
break;
default:
console.error("%s is not supported", c);
break;
}
});