---
title: CGKeyCode
framework: coregraphics
role: symbol
role_heading: Type Alias
path: coregraphics/cgkeycode
---

# CGKeyCode

Represents the virtual key codes used in keyboard events.

## Declaration

```swift
typealias CGKeyCode = UInt16
```

## Discussion

Discussion In macOS, the hardware scan codes generated by keyboards are mapped to a set of virtual key codes that are hardware-independent. Pressing a given key always generates the same virtual key code on any supported keyboard. As keys are pressed, the system uses the virtual key codes to create low-level keyboard events. For information on how to simulate a keyboard event, see the function init(keyboardEventSource:virtualKey:keyDown:).

## See Also

### Data Types

- [CGButtonCount](coregraphics/cgbuttoncount.md)
- [CGCharCode](coregraphics/cgcharcode.md)
- [CGDirectDisplayID](coregraphics/cgdirectdisplayid.md)
- [CGDisplayBlendFraction](coregraphics/cgdisplayblendfraction.md)
- [CGDisplayConfigRef](coregraphics/cgdisplayconfigref.md)
- [CGDisplayCount](coregraphics/cgdisplaycount.md)
- [CGDisplayErr](coregraphics/cgdisplayerr.md)
- [CGDisplayFadeInterval](coregraphics/cgdisplayfadeinterval.md)
- [CGDisplayFadeReservationToken](coregraphics/cgdisplayfadereservationtoken.md)
- [CGDisplayMode](coregraphics/cgdisplaymode.md)
- [CGDisplayReconfigurationCallBack](coregraphics/cgdisplayreconfigurationcallback.md)
- [CGDisplayReservationInterval](coregraphics/cgdisplayreservationinterval.md)
- [CGDisplayStream](coregraphics/cgdisplaystream.md)
- [CGDisplayStreamFrameAvailableHandler](coregraphics/cgdisplaystreamframeavailablehandler.md)
- [CGDisplayStreamUpdate](coregraphics/cgdisplaystreamupdate.md)
