开发者

Simulate Space Bar pressed?

开发者 https://www.devze.com 2023-03-23 00:30 出处:网络
I\'m using this code to simulate a space down/release event in Objective-C: CGEventRef CGEventCreateKeyboardEvent (CGEventSourceRef source, CGKeyCode virtualKey, bool keyDown);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消