发送“副本”;可可中的命令

发布于 2024-08-17 20:00:55 字数 608 浏览 2 评论 0原文

有没有办法发送复制(command-c)指令而不使用cgEvent来模拟击键?我无权访问要从中获取文本的应用程序中的文本字段,因此需要手动复制到剪贴板,并且 cgevent 发布似乎存在错误。

根据 Quartz 文档,要输入大写字母 Z,我应该使用:

CGEventRef event1, event2, event3, event4;
event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);
event3 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, false);
event4 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, false);

但是,如果我将这组指令附加到 NSTimer,它仅在第一次触发时有效。示例输出:

ZzzZzzzzZZzzZ (vs expected ZZZZZZZZZ).

我还可以如何将复制命令发送到活动窗口?

Is there any way to send a copy (command-c) instruction without using a cgEvent to mimic the keystrokes? I don't have access to the text field in the application I want to take text from, so need to replicate manually copying to the clipboard, and there seemss to be a bug with cgevent posting.

According the Quartz documentation, to type a capital Z I should use:

CGEventRef event1, event2, event3, event4;
event1 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, true);
event2 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, true);
event3 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)6, false);
event4 = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)56, false);

However, if I attach this set of instuctions to an NSTimer, it only works the first time it is fired. example output:

ZzzZzzzzZZzzZ (vs expected ZZZZZZZZZ).

How else might I send a copy command to the active window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔一刀 2024-08-24 20:00:55

您可能最好使用辅助功能 API 来触发其他应用程序的“编辑”菜单中的“复制”项,而不是发布原始按键事件。这可能会更可靠。

Rather than posting raw key events, you might be better off using the Accessibility APIs to trigger the Copy item in the other app's Edit menu. This will probably be more reliable.

对风讲故事 2024-08-24 20:00:55

我不确定我是否理解您的代码和应用程​​序代码之间的关系。你是注射什么的吗?您是否有无法执行以下操作的原因:[[window firstResponder] copy:nil]

请再描述一下你在做什么。

I'm not sure I understand the relationship between your code and the application's code. Are you injecting or something? Is there a reason you can't do: [[window firstResponder] copy:nil]?

Describe a little more what you're doing, please.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文