8000 js: report Cmd, and release keys the browser never says came up by benface · Pull Request #698 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content

js: report Cmd, and release keys the browser never says came up - #698

Open
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:web-command-key
Open

benface wants to merge 1 commit into
not-fl3:masterfrom
benface:web-command-key

Conversation

@benface
@benface benface commented Oct 30, 2026
Copy link
Copy Markdown
Contributor

Why

On the web, Cmd (and the Windows key) never reached an app. Browsers name it MetaLeft and MetaRight in KeyboardEvent.code, and into_sapp_keycode only knew OSLeft and OSRight, the names Firefox used before version 118. So KeyCode::LeftSuper never went down, key events never held KeyMods::logo, and Cmd+Z reached an app as a plain Z, after an "Unsupported keyboard key" log for Cmd.

macOS browsers also send no keyup for a key released while Cmd is down, so after Cmd+Z, is_key_down(KeyCode::Z) stayed true until Z was pressed again. A canvas that loses focus with keys down, as when Cmd+Tab switches apps, never hears their keyup either.

Change

  • MetaLeft and OSLeft map to LeftSuper, and MetaRight and OSRight to RightSuper.
  • metaKey sets SAPP_MODIFIER_SUPER, through into_sapp_modifiers, which keydown and keyup now share.
  • gl.js keeps the keys it reported down. When Cmd comes up, every key but the modifiers comes up with it, and when the canvas loses focus, every key comes up.

Verification

In a macroquad game (CHOMP) built for the web, through Playwright on macOS, in Chromium and WebKit:

Before After
Cmd+Z reaches the app as an unknown key, then key_down(Z, 0) key_down(LeftSuper, SUPER), key_down(Z, SUPER)
Cmd up while Z is still down Z stays down Z comes up after Cmd
The canvas loses focus with Cmd down Cmd stays down Cmd comes up

The game's Cmd+Z, Cmd+Shift+Z and Cmd+R (undo, redo, restart) work with it, and Ctrl+Z still does. Playwright's Firefox doesn't start on this Mac, so Firefox wasn't run. Playwright sends its own key events, so the missing keyup was stood in for by never releasing Z before Cmd.

🤖 Generated with Claude Code

Browsers name the Cmd and Windows keys `MetaLeft` and `MetaRight`, and
gl.js only knew their old names, `OSLeft` and `OSRight`, which Firefox
dropped in version 118, so `KeyCode::LeftSuper` never went down and
key events never held `KeyMods::logo`: Cmd+Z reached an app as Z. Both
names now map to Super, and `metaKey` sets the logo modifier.

macOS browsers send no keyup for a key released while Cmd is down, so
after Cmd+Z, Z stayed down until it was pressed again. Every key but
the modifiers now comes up with Cmd. A canvas that loses focus gets
none of its keys' keyups either, as when Cmd+Tab switches apps, so
they all come up with its focus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0