开发者

Sending keystrokes to cocoa app

开发者 https://www.devze.com 2023-02-22 07:28 出处:网络
Is it possible to send keystrokes to a cocoa app? I don\'t want to use AppleScript because I want to do it under the hood, programatically. I开发者_开发技巧s this possible? Thanks.Have a look at these

Is it possible to send keystrokes to a cocoa app? I don't want to use AppleScript because I want to do it under the hood, programatically. I开发者_开发技巧s this possible? Thanks.


Have a look at these calls, but you will need to set code correctly which can be dependent of the currently selected keyboard.

CGEventRef event;
event = CGEventCreateKeyboardEvent (NULL, code, down);
CGEventPost(kCGSessionEventTap, event);
CFRelease(event);

http://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/func/CGEventCreateKeyboardEvent

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号