<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIElement/typeKey(_:modifierFlags:)-9ubn",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(cs)XCUIElement(im)typeKey:modifierFlags:"
  },
  "title" : "typeKey(_:modifierFlags:)"
}
-->

# typeKey(_:modifierFlags:)

Types a single key that a string represents with the flags you specify.

```
@MainActor func typeKey(_ key: String, modifierFlags flags: XCUIElement.KeyModifierFlags)
```

## Parameters

`key`

A string representation of the key to type, or a constant from [`XCUIKeyboardKey`](/documentation/XCUIAutomation/XCUIKeyboardKey) for a key that doesn’t have a single-key string equivalent.

`flags`

A set of modifier flags ([`XCUIElement.KeyModifierFlags`](/documentation/XCUIAutomation/XCUIElement/KeyModifierFlags)) to use when typing the key.

## Discussion

Although `key` is a string, it must represent a single key on a physical keyboard. Strings that resolve to multiple keys raise an error at runtime.

In addition to literal string key representations like `"a"`, `"6"`, and `"["`, keys such as arrow keys, Command, Control, Option, and function keys can be typed using the constants in [`XCUIKeyboardKey`](/documentation/XCUIAutomation/XCUIKeyboardKey).

---

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)