From 809e3e84d65b6d6aa7fc50a3c626714881194b64 Mon Sep 17 00:00:00 2001
From: JelloBagel <41085564+JelloBagel@users.noreply.github.com>
Date: Tue, 24 Nov 2026 14:39:46 -0800
Subject: [PATCH 1/4] Fix macOS shifted key normalization
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---
src/hotkey.ts | 5 ++--
test/test.js | 73 +++++++++++++++++++++++++++++----------------------
2 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/src/hotkey.ts b/src/hotkey.ts
index a31fd3c..167501d 100644
--- a/src/hotkey.ts
+++ b/src/hotkey.ts
@@ -52,9 +52,10 @@ export function eventToHotkeyString(
const altNormalizedKey =
hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? macosSymbolLayerKeys[key] ?? key : key
- // MacOS outputs lowercase characters when `Command+Shift` is held, so we map them back to uppercase if we can
+ // MacOS outputs lowercase characters when a modifier and `Shift` are held, so we map them back to uppercase if we can.
+ // Shift-only events already report the layout's shifted character (e.g. German Shift+7 is '/').
const shiftNormalizedKey =
- hotkeyString.includes('Shift') && matchApplePlatform.test(platform)
+ shiftKey && (ctrlKey || altKey || metaKey) && matchApplePlatform.test(platform)
? macosUppercaseLayerKeys[altNormalizedKey] ?? altNormalizedKey
: altNormalizedKey
diff --git a/test/test.js b/test/test.js
index d26d497..0f4331b 100644
--- a/test/test.js
+++ b/test/test.js
@@ -263,37 +263,47 @@ describe('hotkey', function () {
describe('eventToHotkeyString', function () {
const tests = [
- ['Control+Shift+J', {ctrlKey: true, shiftKey: true, code: 'KeyJ', key: 'J'}],
- ['Control+Shift+j', {ctrlKey: true, shiftKey: true, code: 'KeyJ', key: 'j'}],
- ['Control+j', {ctrlKey: true, code: 'KeyJ', key: 'j'}],
- ['Meta+Shift+p', {key: 'p', metaKey: true, shiftKey: true, code: 'KeyP'}],
- ['Meta+Shift+8', {key: '8', metaKey: true, shiftKey: true, code: 'Digit8'}],
- ['Control+Shift+7', {key: '7', ctrlKey: true, shiftKey: true, code: 'Digit7'}],
- ['Shift+J', {shiftKey: true, code: 'KeyJ', key: 'J'}],
- ['/', {key: '/', code: ''}],
- ['1', {key: '1', code: 'Digit1'}],
- ['Control+Shift+`', {ctrlKey: true, shiftKey: true, key: '`'}],
- ['c', {key: 'c', code: 'KeyC'}],
- ['Shift+S', {key: 'S', shiftKey: true, code: 'KeyS'}],
- ['Shift+!', {key: '!', shiftKey: true, code: 'Digit1'}],
- ['Control+Shift', {ctrlKey: true, shiftKey: true, key: 'Shift'}],
- ['Control+Shift', {ctrlKey: true, shiftKey: true, key: 'Control'}],
- ['Alt+s', {altKey: true, key: 's'}],
- ['Alt+s', {altKey: true, key: 'ß'}, 'mac'],
- ['Alt+Shift+S', {altKey: true, shiftKey: true, key: 'S'}],
- ['Alt+Shift+S', {altKey: true, shiftKey: true, key: 'Í'}, 'mac'],
- ['Alt+ArrowLeft', {altKey: true, key: 'ArrowLeft'}],
- ['Alt+ArrowLeft', {altKey: true, key: 'ArrowLeft'}, 'mac'],
- ['Alt+Shift+ArrowLeft', {altKey: true, shiftKey: true, key: 'ArrowLeft'}],
- ['Alt+Shift+ArrowLeft', {altKey: true, shiftKey: true, key: 'ArrowLeft'}, 'mac'],
- ['Control+Space', {ctrlKey: true, key: ' '}],
- ['Shift+Plus', {shiftKey: true, key: '+'}],
- ['Meta+Shift+X', {metaKey: true, shiftKey: true, key: 'x'}, 'mac'],
- ['Control+Shift+X', {ctrlKey: true, shiftKey: true, key: 'X'}],
- ['Meta+Shift+!', {metaKey: true, shiftKey: true, key: '1'}, 'mac'],
- ['Control+Shift+!', {ctrlKey: true, shiftKey: true, key: '!'}]
+ // Other platforms
+ {expected: '/', event: {key: '/', code: ''}},
+ {expected: '1', event: {key: '1', code: 'Digit1'}},
+ {expected: 'c', event: {key: 'c', code: 'KeyC'}},
+ {expected: 'Shift+J', event: {shiftKey: true, code: 'KeyJ', key: 'J'}},
+ {expected: 'Shift+S', event: {key: 'S', shiftKey: true, code: 'KeyS'}},
+ {expected: 'Shift+!', event: {key: '!', shiftKey: true, code: 'Digit1'}},
+ {expected: 'Shift+Plus', event: {shiftKey: true, key: '+'}},
+ {expected: 'Control+j', event: {ctrlKey: true, code: 'KeyJ', key: 'j'}},
+ {expected: 'Control+Space', event: {ctrlKey: true, key: ' '}},
+ {expected: 'Control+Shift+J', event: {ctrlKey: true, shiftKey: true, code: 'KeyJ', key: 'J'}},
+ {expected: 'Control+Shift+j', event: {ctrlKey: true, shiftKey: true, code: 'KeyJ', key: 'j'}},
+ {expected: 'Control+Shift+7', event: {key: '7', ctrlKey: true, shiftKey: true, code: 'Digit7'}},
+ {expected: 'Control+Shift+`', event: {ctrlKey: true, shiftKey: true, key: '`'}},
+ {expected: 'Control+Shift', event: {ctrlKey: true, shiftKey: true, key: 'Shift'}},
+ {expected: 'Control+Shift', event: {ctrlKey: true, shiftKey: true, key: 'Control'}},
+ {expected: 'Control+Shift+X', event: {ctrlKey: true, shiftKey: true, key: 'X'}},
+ {expected: 'Control+Shift+!', event: {ctrlKey: true, shiftKey: true, key: '!'}},
+ {expected: 'Alt+s', event: {altKey: true, key: 's'}},
+ {expected: 'Alt+ArrowLeft', event: {altKey: true, key: 'ArrowLeft'}},
+ {expected: 'Alt+Shift+S', event: {altKey: true, shiftKey: true, key: 'S'}},
+ {expected: 'Alt+Shift+ArrowLeft', event: {altKey: true, shiftKey: true, key: 'ArrowLeft'}},
+ {expected: 'Meta+Shift+p', event: {key: 'p', metaKey: true, shiftKey: true, code: 'KeyP'}},
+ {expected: 'Meta+Shift+8', event: {key: '8', metaKey: true, shiftKey: true, code: 'Digit8'}},
+
+ // macOS
+ {expected: 'Shift+A', event: {shiftKey: true, key: 'A', code: 'KeyA'}, platform: 'mac'},
+ {expected: 'Shift+/', event: {shiftKey: true, key: '/', code: 'Digit7'}, platform: 'mac'}, // DE keyboard layout
+ {expected: 'Shift+?', event: {shiftKey: true, key: '?', code: 'Minus'}, platform: 'mac'}, // DE keyboard layout
+ {expected: 'Shift+(', event: {shiftKey: true, key: '(', code: 'Digit8'}, platform: 'mac'}, // DE keyboard layout
+ {expected: 'Shift+Plus', event: {shiftKey: true, key: '+', code: 'BracketRight'}, platform: 'mac'}, // DE keyboard layout
+ {expected: 'Control+Shift+?', event: {ctrlKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
+ {expected: 'Alt+s', event: {altKey: true, key: 'ß'}, platform: 'mac'},
+ {expected: 'Alt+ArrowLeft', event: {altKey: true, key: 'ArrowLeft'}, platform: 'mac'},
+ {expected: 'Alt+Shift+S', event: {altKey: true, shiftKey: true, key: 'Í'}, platform: 'mac'},
+ {expected: 'Alt+Shift+ArrowLeft', event: {altKey: true, shiftKey: true, key: 'ArrowLeft'}, platform: 'mac'},
+ {expected: 'Alt+Shift+?', event: {altKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
+ {expected: 'Meta+Shift+X', event: {metaKey: true, shiftKey: true, key: 'x'}, platform: 'mac'},
+ {expected: 'Meta+Shift+!', event: {metaKey: true, shiftKey: true, key: '1'}, platform: 'mac'}
]
- for (const [expected, keyEvent, platform = 'win / linux'] of tests) {
+ for (const {expected, event: keyEvent, platform = 'win / linux'} of tests) {
it(`${JSON.stringify(keyEvent)} => ${expected}`, () => {
return new Promise(resolve => {
document.body.addEventListener('keydown', function handler(event) {
@@ -384,7 +394,8 @@ describe('hotkey', function () {
})
it('works with macos meta+shift plane', async () => {
- setHTML(``)
+ const key = /Mac|iPod|iPhone|iPad/i.test(navigator.platform) ? 'P' : 'p'
+ setHTML(``)
document.dispatchEvent(new KeyboardEvent('keydown', {metaKey: true, shiftKey: true, key: 'p'}))
From 70cfa5892d1f6153c265272b1a92505037b5d81c Mon Sep 17 00:00:00 2001
From: JelloBagel <41085564+JelloBagel@users.noreply.github.com>
Date: Tue, 24 Nov 2026 14:42:07 -0800
Subject: [PATCH 2/4] Remove redundant normalization comment
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---
src/hotkey.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/hotkey.ts b/src/hotkey.ts
index 167501d..43ac50c 100644
--- a/src/hotkey.ts
+++ b/src/hotkey.ts
@@ -53,7 +53,6 @@ export function eventToHotkeyString(
hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? macosSymbolLayerKeys[key] ?? key : key
// MacOS outputs lowercase characters when a modifier and `Shift` are held, so we map them back to uppercase if we can.
- // Shift-only events already report the layout's shifted character (e.g. German Shift+7 is '/').
const shiftNormalizedKey =
shiftKey && (ctrlKey || altKey || metaKey) && matchApplePlatform.test(platform)
? macosUppercaseLayerKeys[altNormalizedKey] ?? altNormalizedKey
From 088f592826d0a0fa4571ce9c87005f1fcd8dc741 Mon Sep 17 00:00:00 2001
From: JelloBagel <41085564+JelloBagel@users.noreply.github.com>
Date: Tue, 24 Nov 2026 16:08:19 -0800
Subject: [PATCH 3/4] Preserve non-letter keys in macOS Shift normalization
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
---
README.md | 3 ++-
src/hotkey.ts | 2 +-
src/macos-uppercase-layer.ts | 28 +---------------------------
test/test.js | 16 +++++++++++++---
4 files changed, 17 insertions(+), 32 deletions(-)
diff --git a/README.md b/README.md
index bd39d48..119b9ba 100644
--- a/README.md
+++ b/README.md
@@ -111,7 +111,8 @@ for (const el of document.querySelectorAll('[data-shortcut]')) {
7. `"Plus"` and `"Space"` are special key names to represent the `+` and ` ` keys respectively, because these symbols cannot be represented in the normal hotkey string syntax.
8. You can use the comma key `,` as a hotkey, e.g. `a,,` would activate if the user typed `a` or `,`. `Control+,,x` would activate for `Control+,` or `x`.
9. `"Shift"` should be included if it would be held and the key is uppercase: ie, `Shift+A` not `A`
- 1. MacOS outputs lowercase key names when `Meta+Shift` is held (ie, `Meta+Shift+a`). In an attempt to normalize this, `hotkey` will automatically map these key names to uppercase, so the uppercase keys should still be used (ie, `"Meta+Shift+A"` or `"Mod+Shift+A"`). **However**, this normalization only works on US keyboard layouts.
+ 1. On macOS, modifier+Shift combinations may report lowercase letters. `hotkey` normalizes ASCII letters to uppercase, so use `"Meta+Shift+A"` or `"Mod+Shift+A"`.
+ 2. Shift normalization leaves other characters unchanged, so use the reported key (for example, `"Meta+Shift+1"` if `event.key` is `"1"`). macOS `Alt` combinations still use a US-layout Option mapping, which may differ on other layouts.
### Example
diff --git a/src/hotkey.ts b/src/hotkey.ts
index 43ac50c..aadaa85 100644
--- a/src/hotkey.ts
+++ b/src/hotkey.ts
@@ -52,7 +52,7 @@ export function eventToHotkeyString(
const altNormalizedKey =
hotkeyString.includes('Alt') && matchApplePlatform.test(platform) ? macosSymbolLayerKeys[key] ?? key : key
- // MacOS outputs lowercase characters when a modifier and `Shift` are held, so we map them back to uppercase if we can.
+ // macOS may report lowercase letters when a modifier and `Shift` are held.
const shiftNormalizedKey =
shiftKey && (ctrlKey || altKey || metaKey) && matchApplePlatform.test(platform)
? macosUppercaseLayerKeys[altNormalizedKey] ?? altNormalizedKey
diff --git a/src/macos-uppercase-layer.ts b/src/macos-uppercase-layer.ts
index 4b835af..e150b70 100644
--- a/src/macos-uppercase-layer.ts
+++ b/src/macos-uppercase-layer.ts
@@ -1,31 +1,5 @@
-/**
- * Map of 'uppercase' symbols to the keys that would be pressed (while holding `Shift`) to type them on MacOS on an
- * English layout. Most of these are standardized across most language layouts, so this won't work 100% in every
- * language but it should work most of the time.
- *
- */
+/** Map ASCII lowercase letters to uppercase for macOS modifier+Shift events. */
export const macosUppercaseLayerKeys: Record = {
- ['`']: '~',
- ['1']: '!',
- ['2']: '@',
- ['3']: '#',
- ['4']: '$',
- ['5']: '%',
- ['6']: '^',
- ['7']: '&',
- ['8']: '*',
- ['9']: '(',
- ['0']: ')',
- ['-']: '_',
- ['=']: '+',
- ['[']: '{',
- [']']: '}',
- ['\\']: '|',
- [';']: ':',
- ["'"]: '"',
- [',']: '<',
- ['.']: '>',
- ['/']: '?',
['q']: 'Q',
['w']: 'W',
['e']: 'E',
diff --git a/test/test.js b/test/test.js
index 0f4331b..5f6994f 100644
--- a/test/test.js
+++ b/test/test.js
@@ -294,14 +294,16 @@ describe('hotkey', function () {
{expected: 'Shift+?', event: {shiftKey: true, key: '?', code: 'Minus'}, platform: 'mac'}, // DE keyboard layout
{expected: 'Shift+(', event: {shiftKey: true, key: '(', code: 'Digit8'}, platform: 'mac'}, // DE keyboard layout
{expected: 'Shift+Plus', event: {shiftKey: true, key: '+', code: 'BracketRight'}, platform: 'mac'}, // DE keyboard layout
- {expected: 'Control+Shift+?', event: {ctrlKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
+ {expected: 'Control+Shift+/', event: {ctrlKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
{expected: 'Alt+s', event: {altKey: true, key: 'ß'}, platform: 'mac'},
{expected: 'Alt+ArrowLeft', event: {altKey: true, key: 'ArrowLeft'}, platform: 'mac'},
{expected: 'Alt+Shift+S', event: {altKey: true, shiftKey: true, key: 'Í'}, platform: 'mac'},
{expected: 'Alt+Shift+ArrowLeft', event: {altKey: true, shiftKey: true, key: 'ArrowLeft'}, platform: 'mac'},
- {expected: 'Alt+Shift+?', event: {altKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
+ {expected: 'Alt+Shift+/', event: {altKey: true, shiftKey: true, key: '/'}, platform: 'mac'},
{expected: 'Meta+Shift+X', event: {metaKey: true, shiftKey: true, key: 'x'}, platform: 'mac'},
- {expected: 'Meta+Shift+!', event: {metaKey: true, shiftKey: true, key: '1'}, platform: 'mac'}
+ {expected: 'Meta+Shift+1', event: {metaKey: true, shiftKey: true, key: '1'}, platform: 'mac'},
+ {expected: 'Meta+Shift+!', event: {metaKey: true, shiftKey: true, key: '!'}, platform: 'mac'},
+ {expected: 'Meta+Shift+/', event: {metaKey: true, shiftKey: true, key: '/'}, platform: 'mac'}
]
for (const {expected, event: keyEvent, platform = 'win / linux'} of tests) {
it(`${JSON.stringify(keyEvent)} => ${expected}`, () => {
@@ -403,6 +405,14 @@ describe('hotkey', function () {
expect(elementsActivated).toEqual(['metashiftplane'])
})
+
+ it('matches the reported non-letter key with meta+shift', function () {
+ setHTML('')
+
+ document.dispatchEvent(new KeyboardEvent('keydown', {metaKey: true, shiftKey: true, key: '1'}))
+
+ expect(elementsActivated).toEqual(['metashift1'])
+ })
})
describe('elements', function () {
From 4633faff4e0cc5d01e830c9ec229a20d4c14ad91 Mon Sep 17 00:00:00 2001
From: JelloBagel <41085564+JelloBagel@users.noreply.github.com>
Date: Wed, 25 Nov 2026 18:22:43 +0000
Subject: [PATCH 4/4] Pin Node CI to supported Ubuntu runner
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
---
.github/workflows/nodejs.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index a719618..5da40e4 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -6,7 +6,7 @@ permissions:
on: [push, pull_request]
jobs:
build:
- runs-on: ubuntu-latest
+ runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0