Skip to content

Commit

Permalink
Use event keys, not codes, to work properly with remapped keyboards
Browse files Browse the repository at this point in the history
When reacting to key events, use the `key` field of the events rather
than the `code` field, because the latter refers to the physical
keyboard key and the former refers to the key as remapped by the user,
which is what we obviously want. If they've remapped their keyboard we
want to obey the remapping!

This is the last piece of the fix for #583. It may also be a fix for
  • Loading branch information
jikamens committed Aug 15, 2023
1 parent e2452da commit 7224ada
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ui/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ const SLOptions = {

document.addEventListener("keydown", (event) => {
if (event.target === document.getElementById("advancedConfigText")) {
if (event.ctrlKey && event.code === "KeyS") {
if (event.ctrlKey && event.key.toLowerCase() === "s") {
saveAdvancedConfig();
}
}
Expand Down
4 changes: 2 additions & 2 deletions ui/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ const SLPopup = {
SLPopup.doSendWithSchedule(schedule);
});
document.addEventListener("keydown", (event) => {
if ((event.ctrlKey || event.metaKey) && event.code === `Digit${i}`) {
if ((event.ctrlKey || event.metaKey) && event.key === i.toString()) {
// Note: also catches Ctrl+Alt+{i}
event.preventDefault();
SLStatic.debug(`Executing shortcut ${i}`);
Expand All @@ -800,7 +800,7 @@ const SLPopup = {
});

document.addEventListener("keydown", function (event) {
if (event.code === "Enter") {
if (event.key === "Enter") {
event.preventDefault();
const inputs = SLPopup.objectifyFormValues();
const schedule = SLPopup.parseInputs(inputs);
Expand Down

0 comments on commit 7224ada

Please sign in to comment.