fix: moonwalking on a mac (and every other key the modifiers broke) - #42
Merged
Merged
Conversation
|
@Colin-Moran is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
benjackwhite
approved these changes
Sep 10, 2026
benjackwhite
left a comment
Collaborator
There was a problem hiding this comment.
this is a solid fix and great PR - thanks!
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The controls were keyed off `event.key`, which is what a keypress produces rather than which key was pressed, and every modifier rewrites it. macOS turns option+a into "å" and every platform turns shift+a into "A", so: - moonwalking (option) never worked with WASD on a mac at all - running (shift) never worked with WASD anywhere - pressing a movement key and then grabbing a modifier stranded the key, because the keyup arrived under a different name than the keydown and never released it. The hog just kept walking. - cmd/ctrl combos were claimed too, so ctrl+d (the debug renderer) also sent him running right, and macOS swallows the keyup while cmd is held, so he never stopped. Resolve from `event.code` instead, which is the physical key and immune to modifier rewriting, keeping an `event.key` fallback for the mobile keyboards that report no code. Also release every held key on blur (browsers don't deliver keyup for keys held when focus is lost) and leave cmd/ctrl chords to the browser. While in here, HedgehogActorControls now actually detaches its listeners. It built a teardown function and threw it away, so every hedgehog leaked two window listeners for the lifetime of the page. Labels the moonwalk key "option" on Apple devices, since "alt" is a key mac users don't have, and documents the controls in the README and the in-game cheat sheet, where they weren't written down anywhere.
benjackwhite
force-pushed
the
fix/mac-modifier-controls
branch
from
September 10, 2026 08:31
913cad7 to
eab85f9
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
the hedgehog has been telling mac users to hold
altfor the better part of ayear. mac users do not have an
alt. worse, the key that is there rewritesevery other key you press, which the controls were not ready for at all.
what was broken
controls.tsmapped keys offevent.key, which is what a keypress producesrather than which key you pressed. hold a modifier and the browser rewrites it:
macOS turns ⌥+a into
"å", and every platform turns shift+a into"A". neitherof those is in the map, so:
Ato moonwalk on a macshift+Dto run with WASDshift, then let go"å"/"A", never matches the keydown, and the key is never released. the hog walks off and never comes backctrl+dto open the debug rendererD, then anythingwhat changed
resolve from
event.codeinstead. that's the physical key, soKeyAstaysKeyAno matter what's held down with it, with anevent.keyfallback for themobile keyboards that don't report a code. then:
blur, because browsers don't send keyup for keysthat were down when the window lost focus. alt-tab mid-stride no longer
sentences him to walk forever.
⌥ optionon apple devices,alteverywhere else.cheat sheet (
cheatcodes), where they had never been documented at all.while i was in there:
HedgehogActorControlsbuilt a teardown function and thenthrew it away, so every hedgehog leaked two window listeners for the life of the
page. it now has a
destroy()andbeforeUnloadcalls it. konami code spawns10,000 hedgehogs, which was 20,000 listeners, which is a lot of retention.
how it was tested
unit tests on the resolver (
keyboard.test.ts,platform.test.ts) covering the⌥/shift rewrites, the no-code fallback, and the label.
then, because "trust me, it walks now" is exactly the kind of pr description
this hedgehog makes fun of, i measured it. built
mainand this branch, andread the player hog's real
walkSpeedout of the running game for each case:awhile ⌥ held-2, still walking0awhileshiftheld-2, still walking0a(moonwalk)0, nothing-1.6, facing rightshift+a(run)0, nothing-4ctrl+d+2, off he goes0-2, still walking0-2/0-2/0, unchangedpnpm test,pnpm lintandpnpm build(engine, playground, extensiontypecheck) all pass. also loaded the unpacked extension and confirmed the fix
ships in
content.js. the extension is where this bit hardest, since ⌘+L and⌘+Tab are keys you actually press on a real website.
not fixed here
the hogwars title screen still tells you to hold
ALTto moonwalk. that branchis a museum piece and i'm not touching it, but it does suggest the assumption
runs deeper than one file.
nothing else changed. arrows,
space, drop-through, fire and web-climbing allbehave exactly as before. he's just no longer at the mercy of whichever modifier
you happened to be resting a finger on.