• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
SOLVED: Synthesizing mouse click events on a hidden WebView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Synthesizing mouse click events on a hidden WebView (From: Keli Hlödversson <email@hidden>)

  • Prev by Date: Re: Catching application errors
  • Next by Date: NSSound command line stutters
  • Previous by thread: Synthesizing mouse click events on a hidden WebView
  • Next by thread: dyld CoreData failure on 10.3 Systems (Gracefully failing on unsupported OS version)
  • Index(es):
    • Date
    • Thread