I'm using this code to simulate a space down/release event in Objective-C:
CGEventRef CGEventCreateKeyboardEvent (CGEventSourceRef source, CGKeyCode virtualKey, bool keyDown);
CGEventRef simulateSpaceUp, simulateSpaceDown;
开发者_高级运维 simulateSpaceDown = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)49, true);
simulateSpaceUp = CGEventCreateKeyboardEvent (NULL, (CGKeyCode)49, false);
I know its incomplete, what am I missing?
UPDATE:
Using this to post:
CGEventPost(kCGSessionEventTap, simulateSpaceDown);
Almost there, though still not working...
You have to post the event using CGEventPost. Just creating it doesn't do anything.
精彩评论