---
title: "typeKey(_:modifierFlags:)"
framework: xcuiautomation
role: symbol
role_heading: Instance Method
path: "xcuiautomation/xcuielement/typekey(_:modifierflags:)-9ubn"
---

# typeKey(_:modifierFlags:)

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

## Declaration

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

## Parameters

- `key`: A string representation of the key to type, or a constant from doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIKeyboardKey for a key that doesn’t have a single-key string equivalent.
- `flags`: A set of modifier flags (doc://com.apple.xcuiautomation/documentation/XCUIAutomation/XCUIElement/KeyModifierFlags) to use when typing the key.

## Discussion

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.

## See Also

### Combining keystrokes

- [typeKey(_:modifierFlags:)](xcuiautomation/xcuielement/typekey(_:modifierflags:)-6gaoi.md)
- [XCUIKeyboardKey](xcuiautomation/xcuikeyboardkey.md)
- [perform(withKeyModifiers:block:)](xcuiautomation/xcuielement/perform(withkeymodifiers:block:).md)
- [XCUIElement.KeyModifierFlags](xcuiautomation/xcuielement/keymodifierflags.md)
