Skip to content

Commit 7531f84

Browse files
feat(www): Enable the usage of modifier keys
Send the modifier keys (ctrl, shift, alt, meta) together with the send key. This allows for example allows to hit crtl-c. Signed-off-by: Tobias Schaffner <[email protected]>
1 parent 453918a commit 7531f84

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

mtda/assets/keysight.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
12: "num",
6161
13: "\n",
6262
16: "shift",
63-
17: "meta",
63+
17: "ctrl",
6464
18: "alt",
6565
19: "pause",
6666
20: "caps",
@@ -156,7 +156,11 @@
156156
else var f = t.toUpperCase();
157157
return {
158158
"char": f,
159-
key: t
159+
key: t,
160+
ctrl: e.ctrlKey,
161+
shift: e.shiftKey,
162+
alt: e.altKey,
163+
cmd: e.metaKey,
160164
}
161165
}, e.exports.unprintableKeys = {
162166
"\b": 1,

mtda/templates/index.html

+9-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,15 @@
106106
<script src="./assets/keysight.js"></script>
107107
<script type=text/javascript>
108108
window.addEventListener("keydown", function(event) {
109-
var key = keysight(event).char;
110-
event.preventDefault();
111-
console.log("#### <KEY> " + key);
112-
$.getJSON('./keyboard-input', {input: key}, function(key) {
109+
var key = keysight(event)
110+
console.log("#### <KEY> " + JSON.stringify(key))
111+
$.getJSON('./keyboard-input', {
112+
input: key.char,
113+
ctrl: key.ctrl,
114+
shift: key.shift,
115+
alt: key.alt,
116+
meta: key.cmd,
117+
}, function(key) {
113118
// do nothing
114119
});
115120
});

mtda/www.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def keyboard_input():
104104
if input in map:
105105
map[input]()
106106
else:
107-
mtda.keyboard.write(input)
107+
mtda.keyboard.press(input,
108+
ctrl=request.args.get('ctrl', False, type=lambda s: s=='true'),
109+
shift=request.args.get('shift', False, type=lambda s: s=='true'),
110+
alt=request.args.get('alt', False, type=lambda s: s=='true'),
111+
meta=request.args.get('meta', False, type=lambda s: s=='true')
112+
)
108113
return ''
109114

110115

0 commit comments

Comments
 (0)