---
title: keyboardShortcut
framework: swiftui
role: symbol
role_heading: Instance Property
path: swiftui/environmentvalues/keyboardshortcut
---

# keyboardShortcut

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

## Declaration

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

## Discussion

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.

## See Also

### Creating keyboard shortcuts

- [keyboardShortcut(_:)](swiftui/view/keyboardshortcut(_:).md)
- [keyboardShortcut(_:modifiers:)](swiftui/view/keyboardshortcut(_:modifiers:).md)
- [keyboardShortcut(_:modifiers:localization:)](swiftui/view/keyboardshortcut(_:modifiers:localization:).md)
- [KeyboardShortcut](swiftui/keyboardshortcut.md)
- [KeyEquivalent](swiftui/keyequivalent.md)
- [EventModifiers](swiftui/eventmodifiers.md)
