onKeyPress(characters:phases:action:)
Performs an action if the user presses one or more keys on a hardware keyboard while the view has focus.
Declaration
nonisolated func onKeyPress(characters: CharacterSet, phases: KeyPress.Phases = [.down, .repeat], action: @escaping (KeyPress) -> KeyPress.Result) -> some View
Parameters
- characters:
The set of characters to match against incoming hardware keyboard events.
- phases:
The key-press phases to match (
.down,.repeat, and.up). The default value is[.down, .repeat]. - action:
The action to perform. The action receives a value describing the matched key event. Return
.handledto consume the event and prevent further dispatch, or.ignoredto allow dispatch to continue.
Return Value
A modified view that binds hardware keyboard input when focused.