为什么我无法将鼠标点击发送到某个窗口?
所以我在这里偶然发现了戴夫的解决方案: http://lists.apple .com/archives/Cocoa-dev/2009/Apr/msg00764.html
这基本上模仿了另一个窗口+发送所有鼠标命令,完成 感觉。我能够将信息发送到 Safari 并浏览网络。
但是当我尝试向游戏窗口(OpenGL 支持)发送鼠标命令时,它根本不执行任何操作。
谁能想到为什么会发生这种情况?以下是实际发送事件的相关代码:
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);
我知道应用程序使用以下内容来识别事件:
result = ReceiveNextEvent?(0, NULL, kEventDurationNoWait, true, &theEvent);
谢谢!
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 actually 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论