开发者

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


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜