告诉系统事件X code到击键? [英] Tell system events to keystroke in Xcode?
问题描述
我在做一个应用程序,其中我需要运行一个code,它会告诉系统事件击键一定的短语。就像在一个AppleScript,我会做:
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"
我不知道如何从X code执行这一点,我真的AP preciate任何帮助。谢谢!
I don't know how to do this from Xcode, and I would really appreciate any help. Thank you!
推荐答案
您可以从code,例如,使用运行AppleScript OSACompileExecute
。另请参见QA1026。
You can run an AppleScript from code, e.g., using OSACompileExecute
. Also see QA1026.
此外,还可以发布使用CGEvent API的键盘事件。随着近年来操作系统,您可能能够避免单独发布每个字母使用 CGEventKeyboardSetUni codeSTRING
。
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
.
这篇关于告诉系统事件X code到击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!