How to go about making app for ipad that makes it into a Mac keyboard [closed]

可紊 提交于 2019-12-01 13:09:25

As for simulating the keypress, there's an easy way to do this using Applescript.

tell application "System Events"
    keystroke "A"
end tell

(You might need to "enable access for assistive devices" in the Accessibility prefpane).

Alternatively, the same script can be run on the command line

osascript -e 'tell app "System Events" to keystroke "a"' 

EDIT: If you're worried about speed, the scripting bridge can help.

#import <Foundation/Foundation.h>
#import <ScriptingBridge/ScriptingBridge.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {  
        id sysEvents = [SBApplication applicationWithBundleIdentifier: @"com.apple.systemevents"];

        [sysEvents keystroke: @"h" using: 'Ksft'];
        [sysEvents keystroke: @"e" using: 0];
        [sysEvents keystroke: @"l" using: 0];
        [sysEvents keystroke: @"l" using: 0];
        [sysEvents keystroke: @"o" using: 0];

        // keyCode might be more suitable for your purposes

        for (int i = 32; i < 64; i++) 
        {
            [sysEvents keyCode: i using: 0];    
        }
    }
}

You can find key codes using this app.

http://manytricks.com/keycodes/

You probably want the CGEventCreateKeyboardEvent() function or similar in the Quartz event services.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!