Sciguy77
Sciguy77

Reputation: 349

Simulate Space Bar pressed?

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...

Upvotes: 1

Views: 951

Answers (1)

user149341
user149341

Reputation:

You have to post the event using CGEventPost. Just creating it doesn't do anything.

Upvotes: 1

Related Questions