From 4bdafe10fd6f031099f2b48f565f8451841c5a98 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 17 Jan 2022 16:23:25 +0700 Subject: [PATCH] use keydown event since keypress is not supported by Android --- docs/examples/webusb-serial/application.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/examples/webusb-serial/application.js b/docs/examples/webusb-serial/application.js index 283121e3..092ec621 100755 --- a/docs/examples/webusb-serial/application.js +++ b/docs/examples/webusb-serial/application.js @@ -76,15 +76,20 @@ let commandLine = document.getElementById("command_line"); - commandLine.addEventListener("keypress", function(event) { + commandLine.addEventListener("keydown", function(event) { + let value; + if (event.keyCode === 13) { if (commandLine.value.length > 0) { addLine('sender_lines', commandLine.value); commandLine.value = ''; } + value = String.fromCharCode(event.keyCode); + } else { + value = event.key; } - port.send(new TextEncoder('utf-8').encode(String.fromCharCode(event.which || event.keyCode))); + port.send(new TextEncoder('utf-8').encode(value)); }); }); })();