fix: bind OEM keys by physical position, not character - #267
Open
ProfetGit wants to merge 1 commit into
Open
Conversation
Keys like the one left of 1 were stored as the character they produce and mapped to a hard-coded VK. That VK is only correct on US layouts: on FI/SE the key is § with VK_OEM_5, not ` with VK_OEM_3. Non-ASCII characters were rejected outright because the token length check counted UTF-8 bytes, so § could not be used as a hotkey or as an auto-press key at all. Punctuation/OEM keys are now stored by physical code and resolved to a VK through the active layout via MapVirtualKeyW, with VkKeyScanW as a fallback for layout-specific characters that arrive without a usable code. Two follow-on fixes for the hold-to-spam-the-same-key case this enables: - The hotkey/auto-press-key conflict guard existed to stop the clicker from retriggering its own hotkey through GetAsyncKeyState. While the low-level hooks run, press state comes from hardware events only (injected input carries AUTOCLICKER_EXTRA_INFO and is skipped), so Hold mode is exempt. Toggle mode still blocks it. - With the duty cycle off the key was pressed and released with a 0ms hold. Desktop apps register that, games do not: they sample the keyboard once per frame. Keyboard cadences of 50ms or longer now floor the hold at 20ms; faster cadences keep 0 so the batched SendInput path stays available. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
§(the key left of1on FI/SE layouts) could not be bound at all — neither as a hotkey nor as the keyboard auto-press key.Two causes:
§withVK_OEM_5, not`withVK_OEM_3.parse_hotkey_main_keyaccepted single-byte tokens only, so any non-ASCII character (2 bytes in UTF-8) fell through toCouldn't recognize '§' as a valid key.Changes
Physical key resolution. OEM/punctuation keys are stored by physical code (
Backquote,Minus,Semicolon, …) rather than by the character they type, and resolved to a VK at parse time withMapVirtualKeyW(scancode, MAPVK_VSC_TO_VK_EX). Display goes throughnavigator.keyboard.getLayoutMap(), so the UI shows the real cap.VkKeyScanWis a fallback for layout-specific characters (§ ö ä ü ç) that arrive without a usable code.Hold mode may reuse the hotkey as the auto-press key. The conflict guard in
start_clicker_innerblocked hotkey == auto-press key to prevent the clicker retriggering its own hotkey viaGetAsyncKeyState. While the low-level hooks run, press state comes from hardware events only — injected input carriesAUTOCLICKER_EXTRA_INFOand is skipped — so Hold mode is exempt. Toggle mode still blocks it, where the loop is real. This is what makes "hold a key to spam that same key" possible (WoW one-button macros, etc.).Minimum keyboard hold. With the duty cycle off, hold was 0 ms: keydown and keyup landed back-to-back. Desktop apps register that; games do not, since they sample the keyboard once per frame (~16 ms at 60 fps). Keyboard cadences at ≥50 ms interval now floor the hold at 20 ms. Faster cadences keep 0 so the batched
SendInputfast path is unaffected.Compatibility
Existing bindings keep working — character tokens (
`,;,\) still parse to their previous VKs. Word-form tokens (backquote,semicolon) now resolve physically, which changes their VK only on non-US layouts, where they were pointing at the wrong key anyway.Testing
cargo test— 79 passed, including new round-trip coverage for physical code tokens andVkKeyScanWresolutionnpm test— 9 passed;tsc --noEmit,eslint,cargo clippy,cargo fmt --checkclean§→§spams at the configured interval into a GSE macro, release stops itNote: injection into an elevated game window requires the clicker to be elevated too (UIPI), which is pre-existing behavior and not changed here.
No version bump or dated changelog heading — changelog entry sits under
# Unreleasedfor you to fold into whatever release you want.🤖 Generated with Claude Code