<!--
{
  "availability" : [
    "iOS: 13.4.0 -",
    "iPadOS: 13.4.0 -",
    "macCatalyst: 13.4.0 -",
    "tvOS: 13.4.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIKey/keyCode",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIKey(py)keyCode"
  },
  "title" : "keyCode"
}
-->

# keyCode

The HID usage code of the key.

```
var keyCode: UIKeyboardHIDUsage { get }
```

## Discussion

Use this property to determine the HID (Human Interface Device) usage code that identifies the key of a USB (Universal Serial Bus) keyboard. For a list of HID usage codes, see [`UIKeyboardHIDUsage`](/documentation/UIKit/UIKeyboardHIDUsage).

Due to the variation of keyboards from language to language, it isn’t feasible to specify exact key mappings for every language. Where the HID usage code list isn’t specific for a key in a particular language, the keyboard firmware uses the closest equivalent key position so manufacturers can produce keyboards for different languages by simply printing different keycaps.

One example is the Y key on a North American keyboard. In Germany, the Z key typically occupies the Y key position. Rather than changing the keyboard firmware to put the Z usage code into that place in the descriptor list, the vendor uses the Y usage code on both the North American and German keyboards.

Because the key mapping may not be exact, use [`charactersIgnoringModifiers`](/documentation/UIKit/UIKey/charactersIgnoringModifiers) instead of [`keyCode`](/documentation/UIKit/UIKey/keyCode) to determine the text value of the key.

---

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)