Input events
Respond to input from a hardware device, like a keyboard or a Touch Bar.
Overview
SwiftUI provides view modifiers that enable your app to listen for and react to various kinds of user input. For example, you can create keyboard shortcuts, respond to a form submission, or take input from the digital crown of an Apple Watch.
[Image]
For design guidance, see Inputs in the Human Interface Guidelines.
Topics
Responding to keyboard input
onKeyPress(_:action:)onKeyPress(phases:action:)onKeyPress(_:phases:action:)onKeyPress(characters:phases:action:)onKeyPress(keys:phases:action:)KeyPress
Creating keyboard shortcuts
keyboardShortcut(_:)keyboardShortcut(_:modifiers:)keyboardShortcut(_:modifiers:localization:)keyboardShortcutKeyboardShortcutKeyEquivalentEventModifiers
Responding to modifier keys
Responding to hover events
onHover(perform:)onContinuousHover(coordinateSpace:perform:)hoverEffect(_:isEnabled:)hoverEffectDisabled(_:)defaultHoverEffect(_:)isHoverEffectEnabledHoverPhaseHoverEffectPhaseOverrideOrnamentHoverContentEffectOrnamentHoverEffect
Modifying pointer appearance
Changing view appearance for hover events
hoverEffect(_:)HoverEffecthoverEffect(_:in:isEnabled:)hoverEffect(in:isEnabled:body:)CustomHoverEffectContentHoverEffectHoverEffectGrouphoverEffectGroup()hoverEffectGroup(_:)hoverEffectGroup(id:in:behavior:)GroupHoverEffectHoverEffectContentEmptyHoverEffectContenthandPointerBehavior(_:)HandPointerBehavior
Responding to submission events
Labeling a submission event
Responding to commands
onMoveCommand(perform:)onDeleteCommand(perform:)pageCommand(value:in:step:)onExitCommand(perform:)onPlayPauseCommand(perform:)onCommand(_:perform:)MoveCommandDirection
Controlling hit testing
Interacting with the Digital Crown
digitalCrownAccessory(_:)digitalCrownAccessory(content:)digitalCrownRotation(_:from:through:sensitivity:isContinuous:isHapticFeedbackEnabled:onChange:onIdle:)digitalCrownRotation(_:onChange:onIdle:)digitalCrownRotation(detent:from:through:by:sensitivity:isContinuous:isHapticFeedbackEnabled:onChange:onIdle:)digitalCrownRotation(_:)digitalCrownRotation(_:from:through:by:sensitivity:isContinuous:isHapticFeedbackEnabled:)DigitalCrownEventDigitalCrownRotationalSensitivity
Managing Touch Bar input
touchBar(content:)touchBar(_:)touchBarItemPrincipal(_:)touchBarCustomizationLabel(_:)touchBarItemPresence(_:)TouchBarTouchBarItemPresence