feat: event-driven keyboard input (no Input Monitoring needed) - #10
Merged
Conversation
sfKeyboard_isKeyPressed polls the OS directly, which on macOS returns false unless the app has the "Input Monitoring" permission — so movement, attack, interact and Escape silently did nothing on a fresh machine. Add an input module that maintains a per-key pressed state from the window's KeyPressed/KeyReleased events (and clears it on focus loss), and replace every sfKeyboard_isKeyPressed call with is_key_held(). The event loops (2D, raycasting and the intro dialog) now feed input_handle_event, and Escape is handled purely from the event. This only needs window focus, so the game is playable everywhere without any system permission. Build warning-free, full Banana scan back to 0, 20/20 tests pass under ASan/UBSan.
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.
Why
sfKeyboard_isKeyPressedpolls the OS keyboard state. On macOS that returnsfalseunless the running app has the Input Monitoring permission, so on afresh machine movement, attack, interact and Escape all silently did nothing
(mouse-driven menus still worked, which is why it looked like "the keyboard is
dead"). Event-based input only needs window focus, so the game plays anywhere.
What
inputmodule:input_handle_event()updates a per-key pressed state fromthe window's
KeyPressed/KeyReleasedevents and clears it onFocusLost;is_key_held()reads that state.sfKeyboard_isKeyPressed(...)is replaced byis_key_held(game, ...)(player + raycast movement, attack, NPC interact, the Ctrl-zoom/inventory
modifier).
input_handle_event,and Escape is handled straight from the event.
game_tgains akeystate[sfKeyCount]array (zero-initialised).No keybindings or controls change — only how a held key is detected.
Verification
make re: warning-free.make tests_run/make tests_asan: 20/20, no ASan/UBSan findings.Please test (behaviour change)
This changes the input model, so a quick play is worth it:
Escape to open/close the pause menu, Ctrl+wheel zoom.
symptom).