问题
I was wondering if it would be possible to simulate keyboard events - like key down and key up characters - and send them to the iOS device. Basically, I want to simulate a user pressing a key on the keyboard.
回答1:
have a look at "Automated GUI testing for iOS", for example Automated testing for iPhone and How about UI automation testing for iOS app with instruments & Javascripts
You might not want a full blown automated test solution, but that way you can simulate your keyboard events.
There is also a blogpost mentioned: http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/
回答2:
I don't think that's possible. But you could write code in textfield delegate or use NSNotificationCenter to get notification of each keypress. If that's what you are looking for.
来源:https://stackoverflow.com/questions/11339004/programmatically-simulate-keyboard-events-on-the-iphone