From b5ccb0c9afb17a566b0be172737cac1147ea2d8b Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 23 Nov 2022 22:27:54 +0000 Subject: [PATCH] js: Add actions for more keys in menus I expect Escape to exit the menu, and SoftRight should do that as well for KaiOS. Backspace goes up one level through the menus, again because that's conventional on KaiOS and not too confusing elsewhere. --- emccpre.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/emccpre.js b/emccpre.js index cf01c51..e5cbb05 100644 --- a/emccpre.js +++ b/emccpre.js @@ -458,7 +458,8 @@ function initPuzzle() { var cs = window.getComputedStyle(menu); return cs.display == "flex" && cs.flexDirection == "row"; } - if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter"] + if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Enter", + "Escape", "Backspace", "SoftRight"] .includes(event.key)) return; if (ishorizontal(thismenu)) { @@ -494,11 +495,17 @@ function initPuzzle() { else if (event.key == "ArrowLeft") targetitem = parentitem_sideways || (parentitem_up && prevmenuitem(parentitem_up)); + else if (event.key == "Backspace") + targetitem = parentitem; } if (targetitem) targetitem.firstElementChild.focus(); else if (event.key == "Enter") event.target.click(); + else if (event.key == "Escape" || event.key == "SoftRight" || + event.key == "Backspace") + // Leave the menu entirely. + onscreen_canvas.focus(); // Prevent default even if we didn't do anything, as long as this // was an interesting key. event.preventDefault();