<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/EnvironmentValues/keyboardShortcut",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17EnvironmentValuesVAAE16keyboardShortcutAA08KeyboardF0VSgvp"
  },
  "title" : "keyboardShortcut"
}
-->

# keyboardShortcut

The keyboard shortcut that buttons in this environment will be triggered
with.

```
var keyboardShortcut: KeyboardShortcut? { get }
```

## Discussion

This is particularly useful in button styles when a button’s appearance
depends on the shortcut associated with it. On macOS, for example, when
a button is bound to the Return key, it is typically drawn with a
special emphasis. This happens automatically when using the built-in
button styles, and can be implemented manually in custom styles using
this environment key:

```
private struct MyButtonStyle: ButtonStyle {
    @Environment(\.keyboardShortcut)
    private var shortcut: KeyboardShortcut?

    func makeBody(configuration: Configuration) -> some View {
        let labelFont = Font.body
            .weight(shortcut == .defaultAction ? .bold : .regular)
        configuration.label
            .font(labelFont)
    }
}
```

If no keyboard shortcut has been applied to the view or its ancestor,
then the environment value will be `nil`.

---

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)