Skip to content

Commit

Permalink
feat(www): Enable the usage of modifier keys
Browse files Browse the repository at this point in the history
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 <tobias.schaffner@siemens.com>
  • Loading branch information
TobiasSchaffner committed Mar 6, 2024
1 parent 453918a commit 7531f84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions mtda/assets/keysight.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
12: "num",
13: "\n",
16: "shift",
17: "meta",
17: "ctrl",
18: "alt",
19: "pause",
20: "caps",
Expand Down Expand Up @@ -156,7 +156,11 @@
else var f = t.toUpperCase();
return {
"char": f,
key: t
key: t,
ctrl: e.ctrlKey,
shift: e.shiftKey,
alt: e.altKey,
cmd: e.metaKey,
}
}, e.exports.unprintableKeys = {
"\b": 1,
Expand Down
13 changes: 9 additions & 4 deletions mtda/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,15 @@
<script src="./assets/keysight.js"></script>
<script type=text/javascript>
window.addEventListener("keydown", function(event) {
var key = keysight(event).char;
event.preventDefault();
console.log("#### <KEY> " + key);
$.getJSON('./keyboard-input', {input: key}, function(key) {
var key = keysight(event)
console.log("#### <KEY> " + JSON.stringify(key))
$.getJSON('./keyboard-input', {
input: key.char,
ctrl: key.ctrl,
shift: key.shift,
alt: key.alt,
meta: key.cmd,
}, function(key) {
// do nothing
});
});
Expand Down
7 changes: 6 additions & 1 deletion mtda/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ def keyboard_input():
if input in map:
map[input]()
else:
mtda.keyboard.write(input)
mtda.keyboard.press(input,
ctrl=request.args.get('ctrl', False, type=lambda s: s=='true'),
shift=request.args.get('shift', False, type=lambda s: s=='true'),
alt=request.args.get('alt', False, type=lambda s: s=='true'),
meta=request.args.get('meta', False, type=lambda s: s=='true')
)
return ''


Expand Down

0 comments on commit 7531f84

Please sign in to comment.