---
title: keyCode
framework: appkit
role: symbol
role_heading: Instance Property
path: appkit/nsevent/keycode
---

# keyCode

The virtual code for the key associated with the event.

## Declaration

```swift
var keyCode: UInt16 { get }
```

## Discussion

Discussion Raises an NSInternalInconsistencyException if sent to a non-key event. The property’s value is hardware-independent. The value returned is the same as the value returned in the kEventParamKeyCode when using Carbon Events.

## See Also

### Related Documentation

- [keyEvent(with:location:modifierFlags:timestamp:windowNumber:context:characters:charactersIgnoringModifiers:isARepeat:keyCode:)](appkit/nsevent/keyevent(with:location:modifierflags:timestamp:windownumber:context:characters:charactersignoringmodifiers:isarepeat:keycode:).md)

### Getting key event information

- [characters](appkit/nsevent/characters.md)
- [charactersIgnoringModifiers](appkit/nsevent/charactersignoringmodifiers.md)
- [characters(byApplyingModifiers:)](appkit/nsevent/characters(byapplyingmodifiers:).md)
- [keyRepeatDelay](appkit/nsevent/keyrepeatdelay.md)
- [keyRepeatInterval](appkit/nsevent/keyrepeatinterval.md)
- [specialKey](appkit/nsevent/specialkey-swift.property.md)
- [Function-Key Unicode Values](appkit/function-key-unicode-values.md)
- [NSEvent.SpecialKey](appkit/nsevent/specialkey-swift.struct.md)
- [isARepeat](appkit/nsevent/isarepeat.md)
