Repository navigation
refactor(input): Use KeyState and simplify keyboard state handling - #3233
CryoTheRenegade wants to merge 3 commits into
Conversation
PR Summary by QodoPrevent stuck modifier combos on out-of-order key releases
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper |
[Low impact] The PR appears safe to merge; no new actionable issues were found.
|
xezon
left a comment
There was a problem hiding this comment.
I assume this was entirely generated by LLM? It looks like slop the way the new logic is laid out. It is incomprehensible and unmaintainable. It needs to be unsloppified.
|
How do we know the new generated revision is no slop? |
|
Fair criticism. I used LLM assistance on the first pass, and I should have reviewed and simplified the result before asking you to review it. I own that. I’ve since rewritten the fix. The hotkey translator is stateless now. Modifier press state lives in |
|
I tried to understand this change but I was unable to. It is lacking context. What was the issue and how was it reproduced, how was it fixed and why is it fixed the way it was fixed. |
|
I've reworded the PR description with a simple example and an explanation of the cause, the fix, and why the state is stored in |
| @@ -74,33 +73,15 @@ GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessage | |||
|
|
|||
| if ( t == GameMessage::MSG_RAW_KEY_UP) | |||
There was a problem hiding this comment.
Would MSG_RAW_KEY_DOWN perhaps be an option for hotkeys? All the MetaEvents are key down events. Or is there a good reason why hotkey needs to be posted on down?
There was a problem hiding this comment.
Key-down could work. I found no comment explaining why hotkeys use key-up. I kept the current timing for now.
There was a problem hiding this comment.
I suggest test MSG_RAW_KEY_DOWN. It would be the simpler option and get rid of the new stuff you added to accomodate this event. Players will also be happier if their key presses register faster.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. WalkthroughThe changes add a ChangesKeyboard input state and message handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Keyboard
participant HotKeyTranslator
participant MetaEventTranslator
Keyboard->>HotKeyTranslator: Send raw key-down with key state
HotKeyTranslator->>HotKeyTranslator: Filter modifier and autorepeat states
HotKeyTranslator->>MetaEventTranslator: Continue message translation
Suggested reviewers: Merge Risk:
|
xezon
left a comment
There was a problem hiding this comment.
Ok I lost a oversight on this over time. If i am not mistaken this change now does 3 or more things:
- a KeyState type refactor (which is nice)
- Hotkey press fix
- Alt Tab key fix
And maybe something else.
Can you split all of these things into clean individual commits in an order that makes sense?
67b80bd to
b4ed7f3
Compare
|
I've split the changes into four commits, in this order:
|
xezon
left a comment
There was a problem hiding this comment.
Looks promising. The split makes not entirely clear what a refactor is and what not, as it seems some refactors are mingled with non-refactor commits.
b4ed7f3 to
e52d4a4
Compare
| @@ -550,6 +550,16 @@ void MetaEventTranslator::onKeyEvent(const GameMessage *msg, GameMessageDisposit | |||
| { | |||
| onKeyPressed(disp, systemKeyState, keyType, keyModState); | |||
| } | |||
|
|
|||
| // TheSuperHackers @fix Preserve overlapping GUI hotkeys without suppressing the meta action | |||
There was a problem hiding this comment.
Why is this changed? What is the practical benefit here? Are you just following what the LLM tells you?
There was a problem hiding this comment.
The block keeps a GUI hotkey working when the same plain key also has a key-down meta mapping. For example, E selects matching units, and a button also uses hotkey E. MetaEventTranslator (20) destroys the E press before HotKeyTranslator (25) sees it. Before this PR, the button still fired on key-up. After hotkeys moved to key-down, it would never fire. A simpler fix is to attach HotKeyTranslator before MetaEventTranslator and always return KEEP_MESSAGE. Both actions still run, and I can remove MSG_GUI_HOTKEY. Your earlier objection was to a reorder that destroyed the message, and this version doesn't.
There was a problem hiding this comment.
I cannot think of a good reason why the game should explicitly allow double key mappings. Meta Events and Hot Keys need to be exclusive key mappings.
It is a fair observation that this changes input behavior which I have not considered previously. How about we add a PRESERVE_RETAIL_INPUT=1 define that keeps Hot Keys on Key Up, otherwise it uses Key Down and gets shadowed by Meta Events. This prevents double key mapping with PRESERVE_RETAIL_INPUT=0.
For original English key mappings the PRESERVE_RETAIL_INPUT=0 is not a concern. For other languages it is, because there are a number of key mapping conflicts. These are fixed in data.
Or instead of PRESERVE_RETAIL_INPUT=0, we can make it a new user option TriggerHotKeyOnDown=yes/no
There was a problem hiding this comment.
we can make it a new user option TriggerHotKeyOnDown=yes/no
I like this better, I'll update this pr with this
a8f164a to
a15efbf
Compare
xezon
left a comment
There was a problem hiding this comment.
Commit 5 looks like it should be folded in one of the earlier commits where isCtrlShiftAltKey was added.
|
If there was an update, it appears to be not pushed |
9a103e7 to
e6e01ce
Compare
pushed |
|
May I suggest to split this 4 commit review into 4 pull requests so we can finalize each of them individually? I think this will get us quicker to get it done. |
e6e01ce to
97fa3bc
Compare
Introduce KeyState and the combined modifier mask. Update the keyboard, meta-event, and hotkey types. Simplify the hotkey modifier check and name the buffered key and physical-modifier helper without changing event timing or modifier capture.
97fa3bc to
1c6bbb0
Compare
…dateKeys Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…StateData comment Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This is the
KeyStaterefactor, with no behavior change. The modifier key fixes from the earlier version of this pull request will follow in separate pull requests.Summary
Keyboard::setKeyStateDatanow takes aKeyStateinstead of anUnsignedByte. It has no callers, so nothing changes at runtime.MSG_RAW_KEY_*comments drop "uses Microsoft VK_ codes".KeyDefTypeholds DirectInputDIK_*codes.Evidence
After: same events and modifier capture, no behavior change.
Keyboard.cpp,HotKey.cpp,MetaEvent.cpp,Mouse.cpp,W3DDisplay.cppandWin32DIKeyboard.cpp, main vs this branch, ClangCL and VC6 Release, both games:Mouse,W3DDisplayandWin32DIKeyboard: identical.getKeyStateBit,setKeyStateData,getKeyModState,onKeyPressed: only the mangled names change, from the new parameter types.HotKeyTranslator::translateGameMessage: the three mask tests become onetest 0x4fc, which covers the same bits.Keyboard::updateKeys: VC6 compilesisCtrlShiftAltKeyto a jump table and now calls two of the inlinedemitRawKeyUpIfDowncopies out of line. The calls and their order are the same.Council review
Rounds: 2
🤖 Generated with Claude Code