Is it possible to send Keystrokes to an IoS device?

In MacOS I can achieve this via

func sendKeyStrike(_ keyCode: CGKeyCode, useCommandFlag: Bool) {
                let sourceRef = CGEventSource(stateID: .combinedSessionState)

                if sourceRef == nil {
                    NSLog("FakeKey: No event source")
                    return
                }

                let keyDownEvent = CGEvent(keyboardEventSource: sourceRef,
                                           virtualKey: keyCode,
                                           keyDown: true)
                if useCommandFlag {
                    keyDownEvent?.flags = .maskCommand
                }

                let keyUpEvent = CGEvent(keyboardEventSource: sourceRef,
                                         virtualKey: keyCode,
                                         keyDown: false)

                keyDownEvent?.post(tap: .cghidEventTap)
                keyUpEvent?.post(tap: .cghidEventTap)
            }

Is there a function call either in XCUITest or any other framework to achieve keyboard strokes in IOS?

IOS Seems to have HID keycodes but I just can't find a way to send them to the device. Either through XCUITest or any other framework. (I am ok with simulating a HID device using python or something else to command my iOS device as well.

Replies

Are you trying to do this solely for the purposes of testing? Or do you want to ship an app that does this?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Only testing not planning to ship anything.

I have an IOS Device which I want to pass keystrokes too.... So I can simulate user input in En, German, Chinese etc.

Any idea?

and ya the send_keys function is not what I am looking for, It does not send actual key events as far as I understand :(.

In a UI testing context, can use the XCUITest method typeText for this: https://developer.apple.com/documentation/xctest/xcuielement/1500968-typetext