<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameController",
  "identifier" : "/documentation/GameController/GCKeyboardInput/button(forKeyCode:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Game Controller"
    ],
    "preciseIdentifier" : "c:objc(cs)GCKeyboardInput(im)buttonForKeyCode:"
  },
  "title" : "button(forKeyCode:)"
}
-->

# button(forKeyCode:)

Returns the button element for the specified key code.

```
func button(forKeyCode code: GCKeyCode) -> GCControllerButtonInput?
```

## Parameters

`code`

The code for the keyboard button element.

## Return Value

The keyboard button element that this profile defines for the specified key code.

## Discussion

Alternatively, you can get a button element for a key using the [`subscript(_:)`](/documentation/GameController/GCPhysicalInputProfile/subscript(_:)) notation that you inherit from [`GCPhysicalInputProfile`](/documentation/GameController/GCPhysicalInputProfile), as in `keyboard[GCKeyUpArrow]`.

---

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)