我需要从 Today Extension App 发送击键,所以我是这样写的。
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef f4 = CGEventCreateKeyboardEvent(source, kVK_F4, true);
CGEventSetFlags(f4, kCGEventFlagMaskControl);
CGEventTapLocation location = kCGHIDEventTap;
CGEventPost(location, f4);
CFRelease(f4);
CFRelease(source);`
我在 .entitlements 文件中写了“com.apple.systemevents”。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.systemevents</string>
</array>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
但是,它没有用。
请告诉我如何做到这一点。
谢谢。