MacOS X是否可以将鼠标点击发送到特定窗口?
我已设法通过CGPostMouseEvent
向整个屏幕发送点击。
我想要控制的窗口相互重叠,所以我的下一个想法是在触发点击之前将正确的窗口带到前面。它可以工作,但最终会一团糟......; - )
答案 0 :(得分:4)
可以通过未记录的
将事件发送到Cocoa应用程序CGEventPostToPSN
以下是Dave Keck的一些代码示例。他发布了一个小应用程序on the mailing list。
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];
CGEventPostToPSN(&psn, CGEvent);
要归档它,我在pastie.org上粘贴了more source code
答案 1 :(得分:1)
您可以使用Accessibility APIs。
它有点复杂,但它应该有用。
答案 2 :(得分:1)
也许您可以使用Window Manager API: SetUserFocusWindow()然后创建鼠标事件。