---
title: "button(forKeyCode:)"
framework: gamecontroller
role: symbol
role_heading: Instance Method
path: "gamecontroller/gckeyboardinput/button(forkeycode:)"
---

# button(forKeyCode:)

Returns the button element for the specified key code.

## Declaration

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

## Parameters

- `code`: The code for the keyboard button element.

## Return Value

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

## Discussion

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

## See Also

### Accessing Buttons

- [isAnyKeyPressed](gamecontroller/gckeyboardinput/isanykeypressed.md)
- [GCKeyCode](gamecontroller/gckeycode.md)
- [Keycode Constants](gamecontroller/keycode-constants.md)
