Send a MouseEvent to a NSView (WebView) from code
i am try开发者_JAVA技巧ing to send mouseevent (MouseClick or RightMouseClick) to a NSView... in my case a WebView, that contains a loaded Website. I want to script some clicks on links etc. How is it possible to create a NSEvent and send it to the WebView to perform clicks?
Thanks a lot
ksman
This is a bit late; maybe you found it, maybe you didn't. I recently had to figure this out, though, so I'll document it here and hopefully help someone.
NSPoint where;
where.x = x;
where.y = y;
NSView* resp = [someView hitTest:where];
NSEventType evtType = NSLeftMouseDown;
NSEvent *mouseEvent = [NSEvent mouseEventWithType:evtType
location:where
modifierFlags:nil
timestamp:GetCurrentEventTime()
windowNumber:0
context:[o->helper context]
eventNumber:nil
clickCount:1
pressure:nil];
[resp mouseDown:mouseEvent];
精彩评论