diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-11-26 23:08:31 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2023-01-19 20:34:48 +0000 |
| commit | f693794ff543cb0765ca115d76376bad8e2f5190 (patch) | |
| tree | 88512c896a131bee8a8b2b53fef9956f990ed3bc | |
| parent | f9449af87a4f5420aa7683d3f15110bfa2f1bf17 (diff) | |
| download | puzzles-f693794ff543cb0765ca115d76376bad8e2f5190.zip puzzles-f693794ff543cb0765ca115d76376bad8e2f5190.tar.gz puzzles-f693794ff543cb0765ca115d76376bad8e2f5190.tar.bz2 puzzles-f693794ff543cb0765ca115d76376bad8e2f5190.tar.xz | |
js: Make soft-key labels generate key events when clicked
This makes the app page a little easier to test on desktop browsers that
don't have SoftLeft and SoftRight keys.
| -rw-r--r-- | emccpre.js | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -567,6 +567,25 @@ function initPuzzle() { } }, true); + // Arrange that the softkey labels are clickable. This logically + // belongs as a click handler, but by the time the click event + // fires, the input focus is in the wrong place. + function button_to_key(key) { + return function(mevent) { + mevent.stopPropagation(); + mevent.preventDefault(); + var kevent = new KeyboardEvent("keydown", { + key: key, view: window, bubbles: true}); + document.activeElement.dispatchEvent(kevent); + }; + } + for (var elem of document.querySelectorAll(".lsk")) + elem.addEventListener("mousedown", button_to_key("SoftLeft")); + for (var elem of document.querySelectorAll(".csk")) + elem.addEventListener("mousedown", button_to_key("Enter")); + for (var elem of document.querySelectorAll(".rsk")) + elem.addEventListener("mousedown", button_to_key("SoftRight")); + document.addEventListener("keydown", function(event) { // Key to open the menu on KaiOS. if (event.key == "SoftRight" && |