Skip to content

feat: add pygame keyboard input with intuitive key bindings#397

Open
mrosseel wants to merge 5 commits into
brickbots:mainfrom
mrosseel:feature/pygame-keymap
Open

feat: add pygame keyboard input with intuitive key bindings#397
mrosseel wants to merge 5 commits into
brickbots:mainfrom
mrosseel:feature/pygame-keymap

Conversation

@mrosseel
Copy link
Copy Markdown
Collaborator

@mrosseel mrosseel commented Mar 17, 2026

Summary

  • Add pygame-based keyboard input support for development/testing without hardware keypad
  • Map intuitive key bindings (arrow keys, enter, escape, etc.) to PiFinder button events
  • Enable with --keyboard local flag

Test plan

  • Run with --keyboard local --camera debug and verify all key bindings work
  • Verify no impact when using hardware keypad (default mode)

🤖 Generated with Claude Code

When using a pygame display (-fh), capture keyboard events directly
in the main event loop instead of relying on PyHotKey/pynput, which
cannot access the keyboard on Wayland.

Key mapping:
- +/= and - for PLUS/MINUS (intuitive, matches the button labels)
- Enter/Space/Z for SQUARE (select)
- Ctrl+key for ALT_ variants (emulates SQUARE+key on hardware keypad)
- Arrow keys, number keys, M for LNG_SQUARE unchanged

When pygame display is active with --keyboard local, uses keyboard_none
since the main loop handles key capture directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jscheidtmann
Copy link
Copy Markdown
Collaborator

jscheidtmann commented Mar 17, 2026

Is that a display keyboard (that shows the keyboard binding in a UI)?

I created already some extensive keybindings, see the comment at the top of keyboard_local.py

@mrosseel
Copy link
Copy Markdown
Collaborator Author

Is that a display keyboard (that shows the keyboard binding in a UI)?

I created already some extensive keybindings, see the comment at the top of keyboard_local.py

hi, no it's not a visualisation, pyhotkey does not work on wayland so I figured a pygame approach to steer the pygame window might be cleaner.

I am working on some visualisation though, but that's not something expected to be checked in.

@jscheidtmann
Copy link
Copy Markdown
Collaborator

Maybe this fixes my woes with website testing: pyhotkey on Mac delivers keypresses, even if the window is not focused. Hmm, need to look into a null display.

@brickbots
Copy link
Copy Markdown
Owner

Maybe this fixes my woes with website testing: pyhotkey on Mac delivers keypresses, even if the window is not focused. Hmm, need to look into a null display.

@jscheidtmann I've just checked in #435 which may be of interest to you! Probably a good base for web testing and includes some shutdown logic

brickbots and others added 2 commits May 25, 2026 18:57
Extract the pygame key-map construction into a module-level
_build_pygame_keymaps() helper so main()'s event loop stays readable. The
per-iteration pygame.event.get() poll and the QUIT->KeyboardInterrupt
shutdown path are unchanged.

Add a comment at the setup site and ADR-0004 explaining why pygame keys are
captured in the main process at all: pygame can only read events from the
window-owning process and pynput/PyHotKey can't reach the keyboard under
Wayland, so the keyboard process stays the no-op keyboard_none.

The preceding origin/main merge supplies keyboard_none's bloom_remap arg
(from brickbots#435), fixing the crash where main.py passed a 4th arg the branch's
keyboard_none didn't accept.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@brickbots
Copy link
Copy Markdown
Owner

@mrosseel I've merged main into this branch and re-organized the initialization out of the main loop code. I've tested it and its very nice to not have it pickup stray keystrokes when the PyGame window is not focused 🙌

I'm ready to merge this if you are!

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.

3 participants