<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/KeyboardShortcut",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI16KeyboardShortcutV"
  },
  "title" : "KeyboardShortcut"
}
-->

# KeyboardShortcut

Keyboard shortcuts describe combinations of keys on a keyboard that the user
can press in order to activate a button or toggle.

```
struct KeyboardShortcut
```

## Topics

### Getting standard shortcuts

[`cancelAction`](/documentation/SwiftUI/KeyboardShortcut/cancelAction)

The standard keyboard shortcut for cancelling the in-progress action
or dismissing a prompt, consisting of the Escape (⎋) key and no
modifiers.

[`defaultAction`](/documentation/SwiftUI/KeyboardShortcut/defaultAction)

The standard keyboard shortcut for the default button, consisting of
the Return (↩) key and no modifiers.

### Creating a shortcut

[`init(_:modifiers:)`](/documentation/SwiftUI/KeyboardShortcut/init(_:modifiers:))

Creates a new keyboard shortcut with the given key equivalent and set of
modifier keys.

[`key`](/documentation/SwiftUI/KeyboardShortcut/key)

The key equivalent that the user presses in conjunction with any
specified modifier keys to activate the shortcut.

[`modifiers`](/documentation/SwiftUI/KeyboardShortcut/modifiers)

The modifier keys that the user presses in conjunction with a key
equivalent to activate the shortcut.

### Creating a localized shortcut

[`init(_:modifiers:localization:)`](/documentation/SwiftUI/KeyboardShortcut/init(_:modifiers:localization:))

Creates a new keyboard shortcut with the given key equivalent and set of
modifier keys.

[`localization`](/documentation/SwiftUI/KeyboardShortcut/localization-swift.property)

The localization strategy to apply to this shortcut.

[`KeyboardShortcut.Localization`](/documentation/SwiftUI/KeyboardShortcut/Localization-swift.struct)

Options for how a keyboard shortcut participates in automatic localization.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)