SOLVED: Synthesizing mouse click events on a hidden WebView
SOLVED: Synthesizing mouse click events on a hidden WebView
- Subject: SOLVED: Synthesizing mouse click events on a hidden WebView
- From: Keli Hlödversson <email@hidden>
- Date: Mon, 5 Sep 2005 11:33:35 +0200
After digging around a bit, I've solved the problem.
I couldn't use -postEvent:AtStart: since it requires the window
containing the view to be visible.
Calling -mouseDown: directly on the webView did not work because I
needed to locate the deepest subview inside the web view. This was
possible using -hitTest:
- (void)SimulateMouseClick:(NSPoint)where
{
NSGraphicsContext *context = [NSGraphicsContext currentContext];
NSEvent* mouseDownEvent = [NSEvent
mouseEventWithType:NSLeftMouseDown location:where
modifierFlags:nil timestamp:GetCurrentEventTime()
windowNumber: 0 context:context eventNumber: nil clickCount:1
pressure:nil];
NSEvent* mouseUpEvent = [NSEvent
mouseEventWithType:NSLeftMouseUp location:where
modifierFlags:nil timestamp:GetCurrentEventTime()
windowNumber: 0 context:context eventNumber: nil clickCount:1
pressure:nil];
// -hitTest: returns the deepest subview under the point specified.
// As I'm using the same point for both events, I only call -
hitTest: once.
NSView* subView= [theView hitTest: [mouseUpEvent
locationInWindow]];
if(subView) {
[subView mouseDown: mouseDownEvent];
[subView mouseUp: mouseUpEvent];
}
else
NSLog(@"hitTest returned nil");
}
On 2. sep 2005, at 13.49, Keli Hlödversson wrote:
I'm using a WebView to render HTML into an texture using
NSBitmapImageRep's -initWithFocusedViewRect: to extract the
rendered view.
I also need to simulate mouse click events on the view in order to
follow links. I've tried to create NSEvent objects and post them to
the web view using -mouseDown: and -mouseUp: like the following
code snippet without luck.
NSGraphicsContext *context = [NSGraphicsContext currentContext];
[theView mouseDown: [NSEvent mouseEventWithType:NSLeftMouseDown
location:NSMakePoint(x,y)
modifierFlags:nil timestamp:GetCurrentEventTime()
windowNumber: 0 context:context eventNumber: 1 clickCount:1
pressure:1.0]];
[theView mouseUp: [NSEvent mouseEventWithType:NSLeftMouseUp
location:NSMakePoint(x,y)
modifierFlags:nil timestamp:GetCurrentEventTime()
windowNumber: 0 context:context eventNumber: 1 clickCount:1
pressure:1.0]];
I don't get any errors when I run this and the web view does not
react in any way.
Any ideas how to accomplish this?
--
With kind regards/Med venlig hilsen
Keli Hlodversson
Why does radio sound the way it does today? Why does it sound like
it's been prepped, packaged and served up in easy-to-digest bites,
like tiny bits of Spam stuck on toothpicks?
-- Frank Ahrens
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden