<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGEventSource/keyState(_:key:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGEventSourceKeyState"
  },
  "title" : "keyState(_:key:)"
}
-->

# keyState(_:key:)

Returns a Boolean value indicating the current keyboard state of a Quartz event source.

```
class func keyState(_ stateID: CGEventSourceStateID, key: CGKeyCode) -> Bool
```

## Parameters

`stateID`

The source state to access. Pass one of the constants listed in [`CGEventSourceStateID`](/documentation/CoreGraphics/CGEventSourceStateID).

`key`

The virtual key code to test.

## Return Value

If `true`, the key is down. If `false`, the key is up.

## Discussion

---

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)