Skip to content

Commit

Permalink
Merge pull request #130 from Blipz/master
Browse files Browse the repository at this point in the history
Better support for non-QWERTY keyboards
  • Loading branch information
Azgaar committed Sep 5, 2023
2 parents d065a76 + 6063fa9 commit 7121a2c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/WindowEvents.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@
// keyboard shortcuts
function handleKeydown(event) {
const code = event.code;
const ctrl = event.ctrlKey;
const reserved = ["Backspace", "Enter", "KeyZ", "KeyX", "KeyS", "KeyP", "KeyJ", "F1", "Escape"];
if (!ctrl && !reserved.includes(code)) return;
const action = /^[a-z]$/i.test(event.key) ?
keybinding["Key" + event.key.toUpperCase()] : // for latin keyboards (including non-QWERTY)
keybinding[event.code]; // for non-latin keyboards
if (!action) return;
const active = document.activeElement.tagName;
if (active === "INPUT" || active === "SELECT" || active === "TEXTAREA") return;
event.preventDefault();
const action = keybinding[code];
if (action) action(ctrl);
action(event.ctrlKey);
}
function handleTouchStart(event) {
Expand Down

0 comments on commit 7121a2c

Please sign in to comment.