至于模拟按键,有一个简单的方法来使用Applescript来做到这一点。
tell application "System Events"
keystroke "A"
end tell
(您可能需要在辅助功能prefpane为“启用辅助设备的访问”)。
或者,相同的脚本可以在命令行上运行
osascript -e 'tell app "System Events" to keystroke "a"'
编辑:如果您担心速度,脚本桥可以提供帮助。
#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];
}
}
}
你可以找到使用这个程序的关键代码。
http://manytricks.com/keycodes/
这确实是两个问题,但iOS设备和Mac之间的通信是您可以单独研究的内容,例如http://stackoverflow.com/questions/7127832/robust-real-time-communication-between-ios -app-and-mac-app – joerick 2013-02-23 15:15:03
你提供的这个链接很有帮助,但是听起来好像太慢了,并且过于夸张 – fozbstuios 2013-02-23 15:52:40