Skip to content

feat: Introduce KeyboardCallbacks to new event system - #4114

Open
luanpotter wants to merge 1 commit into
mainfrom
luan.new-keyboard-callbacks
Open

luanpotter wants to merge 1 commit into
mainfrom
luan.new-keyboard-callbacks

Conversation

@luanpotter

Copy link
Copy Markdown
Member

Description

Introduce KeyboardCallbacks to new event system.

Adds a keyboard input layer to the new event system, as per our master plan.

It allows components (and games) to receive KeyPressEvent, KeyHoldEvent and KeyReleaseEvent through onKeyPress, onKeyHold and onKeyRelease. To handle all three in one function, override onKeyboardEvent.

All three events extend a sealed KeyboardEvent. It carries the logicalKey, physicalKey, the set of keys held at the time, the raw event, and helpers for modifier keys (isShiftPressed, isControlPressed, isAltPressed, isMetaPressed), and lock mode helpers (isCapsLockOn, isNumLockOn, isScrollLockOn). character exists only on press and hold events, since Flutter never provides one on release.

Keyboard events have no position, so they go to every listening component (topmost first) unless one sets continuePropagation = false. This is different than taps that default to true, but the same way scrolls, hovers, drags, and some others do.

Events arrive through the GameWidget existing Focus, via a new keyDetector hook on Game. This is purely additive: KeyboardEvents, KeyboardHandler and HardwareKeyboardDetector are untouched for now and work alongside it. I will followup with supporting hardware detection mode on the game level, so component-level callers can use a unified interface, regardless of "focus mode".

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

@luanpotter
luanpotter force-pushed the luan.new-keyboard-callbacks branch from 40885b6 to 0890b1a Compare October 11, 2026 21:03
@luanpotter
luanpotter marked this pull request as ready for review October 11, 2026 21:11
@luanpotter
luanpotter requested a review from ufrshubham October 11, 2026 21:11

This branch has not been deployed

No deployments
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.

1 participant