<!--
{
  "availability" : [
    "Xcode: 16.3.0 -",
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCUIAutomation",
  "identifier" : "/documentation/XCUIAutomation/XCUIElement/perform(withKeyModifiers:block:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "XCUIAutomation"
    ],
    "preciseIdentifier" : "c:objc(cs)XCUIElement(cm)performWithKeyModifiers:block:"
  },
  "title" : "perform(withKeyModifiers:block:)"
}
-->

# perform(withKeyModifiers:block:)

Executes a block of code while holding a combination keystroke.

```
class func perform(withKeyModifiers flags: XCUIElement.KeyModifierFlags, block: () -> Void)
```

## Parameters

`flags`

A set of modifier flags ([`XCUIElement.KeyModifierFlags`](/documentation/XCUIAutomation/XCUIElement/KeyModifierFlags)) to use while executing the block.

`block`

The block to execute.

## Discussion

This method sets and holds the keyboard modifiers you provide while you call methods to click on, drag from, or type into elements in the block.

---

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)