Repository navigation
Release held keys and mouse buttons when the game page loses focus - #46
Open
Sosotess93 wants to merge 3 commits into
Open
Sosotess93 wants to merge 3 commits into
Sosotess93 wants to merge 3 commits into
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
A key or button released while the page is not focused never reaches the game: a screenshot shortcut (Cmd+Shift+4), Cmd+Tab or a click outside the window keeps the keyup for itself. The game then believes the key is still down; a stuck Shift makes every click act in place, so the character no longer walks. The page now remembers which keys and buttons went down and sends their release when the window or the canvas loses focus, or the page is hidden.
Cmd+Shift+4 on macOS does not take focus from the page: the screenshot tool keeps the key-ups of Cmd and Shift, and no blur comes, so Shift stayed down for the game. While Cmd is down, macOS also sends no key-up for the other keys. Every mouse and key event now compares the modifiers it reports with the ones the game holds and releases those that are up. Releasing Cmd releases every held key.
A drag whose release never reached the page (released outside the game, or a release an automation tool did not deliver) left the button down for the game, so later plain moves acted as a held click: the character followed the pointer, a window kept pressing whatever was under it. Each move now compares the buttons it reports with the ones the game holds and releases those that are up before the move, and a release outside the canvas is passed on too.
Sosotess93
force-pushed
the
fix/release-input-on-blur
branch
from
November 23, 2026 10:44
d7f2ee4 to
f2256d4
Compare
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.
Fixes #52.
Problem
A key or mouse button released where the page cannot see it never reaches the game, which keeps believing it is down:
What players see:
Change
recomp/web/index.htmlremembers which keys and buttons went down on the canvas and have not come back up, and sends their release (keyup, or mouseup) through the input ring when:Testing
In game, each case first reproduced on
main:main, clicks do not walk. With this change, the next click sendswalk.blur: the next click walks.main, plain mouse moves sentwalkthree times as the character followed the pointer. With this change, the same moves send nothing, and a real click on the ground still walks.