发送“副本”;可可中的命令
有没有办法发送复制(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能最好使用辅助功能 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.
我不确定我是否理解您的代码和应用程序代码之间的关系。你是注射什么的吗?您是否有无法执行以下操作的原因:
[[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.