Skip to content

Fix modifier-key and media-key macros in keymap parser#8

Open
dallanwagz wants to merge 2 commits into
compukidmike:mainfrom
dallanwagz:fix/issue-5-modifier-keys-clean
Open

Fix modifier-key and media-key macros in keymap parser#8
dallanwagz wants to merge 2 commits into
compukidmike:mainfrom
dallanwagz:fix/issue-5-modifier-keys-clean

Conversation

@dallanwagz

Copy link
Copy Markdown

Fixes #5 plus two related parser bugs in the same family. Both commits
target the same root cause: stale [x+N] != '[' lookahead conditions in
the keymap parser that broke any token whose closing ] is followed by
another token's opening [.

Commits

  1. Fix modifier key macros (3f9f88e) — [ctrl]p, [ctrl][shift]p,
    [gui][shift]s etc. now produce the correct keystroke. Introduces a
    pending_modifier accumulator that collects modifier tokens and applies
    them atomically to the next keystroke.
  2. Fix [eject] typo and chained media-key macros (4abb960) —
    [eject] had its bracket check inverted (!= ']' instead of == ']')
    and was completely non-functional. Eight media tokens still carried the
    stale lookahead the first commit removed from modifiers, so chains like
    [play][next] lost the first token to ascii fall-through.

Validated on hardware (SAMD21G16B)

All five scenarios verified end-to-end on a real DEF CON 29 badge:

  • [ctrl]p → Ctrl+P (Print dialog)
  • [ctrl][shift]p → Ctrl+Shift+P (Command Palette)
  • [gui][shift]s → Snipping Tool overlay (multi-modifier compose)
  • [eject] → no literal text typed (pre-fix typed "eject")
  • [mute][vol-] → mute toggle + volume down (pre-fix typed garbage)

Build: Microchip Studio Release config, ATSAMD21G16B, image fits within the
56 KB flash budget after the 8 KB UF2 bootloader (56536 bytes used, ~800 byte
headroom). See VALIDATION_NOTES.md for build-config notes.

The keymap parser stored modifier tokens as standalone bytes, misaligning
the 2-byte {modifier, keycode} pairs that send_keys() reads with a fixed
stride. Macros using bracketed modifier syntax produced wrong keystrokes
- [ctrl]p sent LEFT_CTRL + LEFT_SHIFT + RIGHT_CTRL instead of Ctrl+P,
and multi-modifier strings like [ctrl][shift]p silently dropped both
modifiers.

Fix introduces a pending_modifier accumulator in serialconsole.c that
collects modifier tokens (one or many) and applies them atomically to
the next keystroke.

Verified end-to-end on real DEF CON 29 badge hardware (SAMD21G16B) via
the serial console:
- Single-modifier macro [ctrl]p accepted and parsed
- Multi-modifier macros [ctrl][shift]p and [gui][shift]s accepted
- [gui][shift]s triggers Snipping Tool on the host (Win+Shift+S),
  confirming both modifiers reach the OS atomically

Also rebuilds Firmware/Compiled/DC29.uf2 - the previously committed
binary was built with the wrong linker script (ORIGIN=0x0) and was
rejected by the badge's UF2 bootloader. See VALIDATION_NOTES.md for
the build configuration and a bootloader-mode gotcha worth knowing
before testing.
Two related parser bugs in serialconsole.c, same family as the issue #5
modifier-key fix in the previous commit:

1. [eject] was completely non-functional. The check
   `newKeystroke[x+5] != ']'` had the operator inverted — for any valid
   `[eject]` token, x+5 IS `]`, so the branch never fired and the token
   fell through to ascii parsing.

2. Eight media tokens ([play], [next], [back], [stop], [eject], [mute],
   [vol+], [vol-]) carried a stale `newKeystroke[x+N] != '['` lookahead
   that was the same broken-by-design pattern the issue #5 fix removed
   from the modifier branches. Effect: chaining adjacent media tokens
   in one macro (e.g. `[play][next]`) silently dropped the first token,
   because the char after its `]` is `[` (start of the next token), so
   the branch was skipped and gibberish ascii ended up in the keymap.

Removing the lookahead makes media tokens behave like the modifier and
F-key tokens already do: each token parses on its own, the loop advances
past it, the next token parses on the next iteration.

No new state, no new helpers — these are the minimal corrections that
make the parser internally consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

macros with modifiers do not work as expected

1 participant