简体   繁体   English

以编程方式执行键盘快捷键-Objective-C

[英]Perform keyboard shortcut programmatically - Objective-C

I'm searching for a way to programmatically perform a keyboard shortcut, just as if the user had clicked the keys himself. 我正在寻找一种以编程方式执行键盘快捷键的方式,就像用户自己单击按键一样。 That shortcut, however, is chosen by the user with a custom control called ShortcutRecorder . 但是,该快捷方式是由用户使用名为ShortcutRecorder的自定义控件选择的。

Is there any way to take the info given by ShortcutRecorder (basically the key code and the flags, I think) and perform that shortcut? 有什么方法可以利用ShortcutRecorder提供的信息(我认为基本上是键代码和标志)来执行该快捷方式?

您可以使用CGEventPost()在系统范围内发布键盘事件,但是用户将必须在“通用访问系统偏好设置”窗格中启用对辅助设备的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM