So I stumbled upon dave's solution here: http://lists.apple.com/archives/Cocoa-dev/2009/Apr/msg00764.html
This basically mimics another window + sends all mouse commands over, makes complete sense. I was able to send info over to safari and navigate the web.
But when I try sending a mouse command to a game window (OpenGL powered), it doesn't do anything, at all.
Can anyone think of why this is occurring? Here is the relevant code that actuall开发者_如何学JAVAy sends the events:
ProcessSerialNumber psn;
CGEventRef CGEvent;
NSEvent *customEvent;
customEvent = [NSEvent mouseEventWithType: [event type]
location: [event locationInWindow]
modifierFlags: [event modifierFlags] | NSCommandKeyMask
timestamp: [event timestamp]
windowNumber: WID
context: nil
eventNumber: 0
clickCount: 1
pressure: 0];
CGEvent = [customEvent CGEvent];
NSAssert(GetProcessForPID(PID, &psn) == noErr, @"GetProcessForPID failed!");
CGEventPostToPSN(&psn, CGEvent);
I know the app uses the following to identify events:
result = ReceiveNextEvent?(0, NULL, kEventDurationNoWait, true, &theEvent);
Thanks!
精彩评论