Tell system events to keystroke in Xcode?

走远了吗. 提交于 2020-01-05 04:24:09

问题


I'm making an application, in which I need to run a code that will tell system events to keystroke a certain phrase. Like in an AppleScript, I would do:

Tell Application "System Events" to keystroke "This is a test"

I don't know how to do this from Xcode, and I would really appreciate any help. Thank you!


回答1:


You can run an AppleScript from code, e.g., using OSACompileExecute. Also see QA1026.

Alternately, you can post keyboard events using the CGEvent APIs. With recent OSes, you may be able to avoid posting each letter individually using CGEventKeyboardSetUnicodeString.



来源:https://stackoverflow.com/questions/3030070/tell-system-events-to-keystroke-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!