Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(www): Allow to use physical keyboard as hid input #403

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 198 additions & 0 deletions mtda/assets/keysight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/* ---------------------------------------------------------------------------
Copyright (c) 2013 by fresheneesz (https://github.com/fresheneesz/keysight)
---------------------------------------------------------------------------
SPDX-License-Identifier: MIT
---------------------------------------------------------------------------
*/

! function(e, n) {
"object" == typeof exports && "object" == typeof module ? module.exports = n() : "function" == typeof define && define.amd ? define(n) : "object" == typeof exports ? exports.keysight = n() : e.keysight = n()
}(this, function() {
return function(e) {
function n(t) {
if (r[t]) return r[t].exports;
var f = r[t] = {
exports: {},
id: t,
loaded: !1
};
return e[t].call(f.exports, f, f.exports, n), f.loaded = !0, f.exports
}
var r = {};
return n.m = e, n.c = r, n.p = "", n(0)
}([function(e) {
function n(e) {
var n = String.fromCharCode(e);
return n in t ? t[n] : n in s ? s[n] : n.toLowerCase()
}
var r = {
"/": "?",
".": ">",
",": "<",
"'": '"',
";": ":",
"[": "{",
"]": "}",
"\\": "|",
"`": "~",
"=": "+",
"-": "_",
1: "!",
2: "@",
3: "#",
4: "$",
5: "%",
6: "^",
7: "&",
8: "*",
9: "(",
0: ")"
},
t = {};
for (var f in r) {
var o = r[f];
t[o] = f
}
var i = {
0: "\\",
8: "\b",
9: " ",
12: "num",
13: "\n",
16: "shift",
17: "meta",
18: "alt",
19: "pause",
20: "caps",
27: "esc",
32: " ",
33: "pageup",
34: "pagedown",
35: "end",
36: "home",
37: "left",
38: "up",
39: "right",
40: "down",
44: "print",
45: "insert",
46: "delete",
91: "cmd",
92: "cmd",
93: "cmd",
96: "num0",
97: "num1",
98: "num2",
99: "num3",
100: "num4",
101: "num5",
102: "num6",
103: "num7",
104: "num8",
105: "num9",
106: "*",
107: "+",
108: "num_enter",
109: "num_subtract",
110: "num_decimal",
111: "num_divide",
112: "f1",
113: "f2",
114: "f3",
115: "f4",
116: "f5",
117: "f6",
118: "f7",
119: "f8",
120: "f9",
121: "f10",
122: "f11",
123: "f12",
124: "print",
144: "num",
145: "scroll",
173: "-",
186: ";",
187: "=",
188: ",",
189: "-",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'",
223: "`",
224: "cmd",
225: "alt",
57392: "ctrl",
63289: "num"
},
a = {};
for (var f in i) {
var u = i[f];
a[u] = f
}
var s = {
"\r": "\n"
},
d = {
num_subtract: "-",
num_enter: "\n",
num_decimal: ".",
num_divide: "/"
};
e.exports = function(e) {
if ("keypress" === e.type) var t = n(e.charCode);
else if (void 0 !== e.keyCode)
if (e.keyCode in i) var t = i[e.keyCode];
else var t = String.fromCharCode(e.keyCode).toLowerCase();
else if (0 === e.charCode) var t = "\n";
if (e.shiftKey && t in r) var f = r[t];
else if (!e.shiftKey || t in a)
if (t in d) var f = d[t];
else var f = t;
else var f = t.toUpperCase();
return {
"char": f,
key: t
}
}, e.exports.unprintableKeys = {
"\b": 1,
num: 1,
shift: 1,
meta: 1,
alt: 1,
pause: 1,
caps: 1,
esc: 1,
pageup: 1,
pagedown: 1,
end: 1,
home: 1,
left: 1,
up: 1,
right: 1,
down: 1,
print: 1,
insert: 1,
"delete": 1,
cmd: 1,
f1: 1,
f2: 1,
f3: 1,
f4: 1,
f5: 1,
f6: 1,
f7: 1,
f8: 1,
f9: 1,
f10: 1,
f11: 1,
f12: 1,
scroll: 1,
ctrl: 1
}
}])
});
19 changes: 12 additions & 7 deletions mtda/keyboard/hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def write(self, what):
self.mtda.debug(3, "keyboard.hid.write()")

bsl = '\\'
bsp = '\b'
ret = '\n'
lower_keys = {
'a': 0x04, 'b': 0x05, 'c': 0x06, 'd': 0x07, 'e': 0x08, 'f': 0x09,
Expand All @@ -228,15 +229,19 @@ def write(self, what):
's': 0x16, 't': 0x17, 'u': 0x18, 'v': 0x19, 'w': 0x1a, 'x': 0x1b,
'y': 0x1c, 'z': 0x1d, '1': 0x1e, '2': 0x1f, '3': 0x20, '4': 0x21,
'5': 0x22, '6': 0x23, '7': 0x24, '8': 0x25, '9': 0x26, '0': 0x27,
ret: 0x28, ' ': 0x2c, '-': 0x2d, '=': 0x2e, '[': 0x2f, ']': 0x30,
bsl: 0x31, ';': 0x33, "'": 0x34, '`': 0x35, ',': 0x36, '.': 0x37,
'/': 0x38
ret: 0x28, bsp: 0x2a, ' ': 0x2c, '-': 0x2d, '=': 0x2e, '[': 0x2f,
']': 0x30, bsl: 0x31, ';': 0x33, "'": 0x34, '`': 0x35, ',': 0x36,
'.': 0x37, '/': 0x38
}
shift_keys = {
'!': 0x1e, '@': 0x1f, '#': 0x20, '$': 0x21, '%': 0x22, '^': 0x23,
'&': 0x24, '*': 0x25, '(': 0x26, ')': 0x27, '_': 0x2d, '+': 0x2e,
'{': 0x2f, '}': 0x30, '|': 0x31, ':': 0x33, '"': 0x34, '~': 0x35,
'<': 0x36, '>': 0x37, '?': 0x38
'A': 0x04, 'B': 0x05, 'C': 0x06, 'D': 0x07, 'E': 0x08, 'F': 0x09,
'G': 0x0a, 'H': 0x0b, 'I': 0x0c, 'J': 0x0d, 'K': 0x0e, 'L': 0x0f,
'M': 0x10, 'N': 0x11, 'O': 0x12, 'P': 0x13, 'Q': 0x14, 'R': 0x15,
'S': 0x16, 'T': 0x17, 'U': 0x18, 'V': 0x19, 'W': 0x1a, 'X': 0x1b,
'Y': 0x1c, 'Z': 0x1d, '!': 0x1e, '@': 0x1f, '#': 0x20, '$': 0x21,
'%': 0x22, '^': 0x23, '&': 0x24, '*': 0x25, '(': 0x26, ')': 0x27,
'_': 0x2d, '+': 0x2e, '{': 0x2f, '}': 0x30, '|': 0x31, ':': 0x33,
'"': 0x34, '~': 0x35, '<': 0x36, '>': 0x37, '?': 0x38
}

for k in what:
Expand Down
8 changes: 8 additions & 0 deletions mtda/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@
</script>
<script src="./assets/jquery.min.js"></script>
<script src="./assets/keyboard.js"></script>
<script src="./assets/keysight.js"></script>
<script type=text/javascript>
window.addEventListener("keydown", function(event) {
var key = keysight(event).char
console.log("#### <KEY> " + key)
$.getJSON('./keyboard-input', {input: key}, function(key) {
// do nothing
});
});
$(function() {
$('a#power-toggle').bind('click', function() {
document.getElementById("power-status-icon").innerHTML = "downloading"
Expand Down
26 changes: 25 additions & 1 deletion mtda/www.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def console_input(data):
def keyboard_input():
mtda = app.config['mtda']
map = {
# virtual keyboard (keyboard.js)
"Esc": mtda.keyboard.esc,
"F1": mtda.keyboard.f1,
"F2": mtda.keyboard.f2,
Expand All @@ -96,7 +97,30 @@ def keyboard_input():
"Left": mtda.keyboard.left,
"Right": mtda.keyboard.right,
"Up": mtda.keyboard.up,
"Down": mtda.keyboard.down
"Down": mtda.keyboard.down,

# physical keyboard (keysight.js)
"esc": mtda.keyboard.esc,
"f1": mtda.keyboard.f1,
"f2": mtda.keyboard.f2,
"f3": mtda.keyboard.f3,
"f4": mtda.keyboard.f4,
"f5": mtda.keyboard.f5,
"f6": mtda.keyboard.f6,
"f7": mtda.keyboard.f7,
"f8": mtda.keyboard.f8,
"f9": mtda.keyboard.f9,
"f10": mtda.keyboard.f10,
"f11": mtda.keyboard.f11,
"f12": mtda.keyboard.f12,
"\b": mtda.keyboard.backspace,
" ": mtda.keyboard.tab,
"caps": mtda.keyboard.capsLock,
"\n": mtda.keyboard.enter,
"left": mtda.keyboard.left,
"right": mtda.keyboard.right,
"up": mtda.keyboard.up,
"down": mtda.keyboard.down,
}
if mtda is not None and mtda.keyboard is not None:
input = request.args.get('input', '', type=str)
Expand Down
Loading