Mimic gestures on iOS and macOS by key codes
Apple has UI recording for automated build testing, but you get that from Xcode and not necessarily on the device.


https://developer.apple.com/videos/play/wwdc2015/406/
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/testing_with_xcode/chapters/09-ui_testing.html


There is quite a bit of setup, but I would start there and once you’re comfortable with the limitations, you can see about trying to make an app to automate from keyboard triggers.