- 代码模拟键盘的return事件
这段代码相当于3秒后按下return键:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CGEventRef push = CGEventCreateKeyboardEvent(NULL, kVK_Return, true);
CGEventPost(kCGHIDEventTap, push);
});
组合键:
//快捷键command+i
CGEventRef push = CGEventCreateKeyboardEvent(NULL, kVK_ANSI_I, true);
CGEventSetFlags(push, kCGEventFlagMaskCommand);
CGEventPost(kCGHIDEventTap, push);
网友评论