将系统事件告诉 Xcode 中的击键? [英] Tell system events to keystroke in Xcode?

查看:18
本文介绍了将系统事件告诉 Xcode 中的击键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个应用程序,我需要在其中运行一个代码,该代码将告诉系统事件击键某个短语.就像在 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"

我不知道如何从 Xcode 执行此操作,我非常感谢您的帮助.谢谢!

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

推荐答案

您可以从代码运行 AppleScript,例如,使用 OSACompileExecute.另请参阅 QA1026.

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

或者,您可以使用 CGEvent API 发布键盘事件.使用最新的操作系统,您可以避免使用 CGEventKeyboardSetUnicodeString 单独发布每个字母.

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.

这篇关于将系统事件告诉 Xcode 中的击键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆