0
我正在嘗試發佈鍵盤事件以觸發空間更改。發佈鍵盤事件
默認情況下,你可以改變空間與控制鍵+你想要改變的空間的數字鍵,這裏是我使用的,但不工作的代碼:
int spaceToChangeTo = 3;
int keyCodeForSpace = space + 17; // keycode 18 = number 1 on the keyboard, and onwards.
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
CGEventRef spaceDownEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)keyCodeForSpace, YES);
CGEventSetFlags(spaceDownEvent, kCGEventFlagMaskControl);
CGEventRef spaceUpEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)keyCodeForSpace, NO);
CGEventPost(kCGAnnotatedSessionEventTap, spaceDownEvent);
CGEventPost(kCGAnnotatedSessionEventTap, spaceUpEvent);
CFRelease(spaceDownEvent);
CFRelease(spaceUpEvent);
CFRelease(source);