[Mono-osx] Generating Mouse Clicks and Keyboard events on Mac

iangardner777 ian.gardner at axure.com
Wed Jul 22 15:57:54 EDT 2009



vivram wrote:
> 
> With .Net I will be able to invoke win32 apis using PInvokes to generate
> mouse clicks at any given point and keyboard events.
> Is it possible using Mono on Mac?
> 
Check out NSEvent's static method
mouseEventWithType:location:modifierFlags:timestamp:windowNumber:context:eventNumber:clickCount:pressure:
in order to create the event.

Most of the parameters in here can just be dummy's depending on what you are
trying to accomplish. In fact I simply got the correct window number and
location. I also bothered getting the time stamp right using microseconds,
but actually I am not even sure that it is right and you can most likely
just put 0 in there for most purposes, so you shouldn't have to bother.

Once you have created your Event use NSWindow's postEvent:atStart:

Note: If you send an event to a Windows control and the location is off of
your control, it will automatically shrink the point of the click to the
control, however since the postEvent method is handled by the NSWindow on
the Mac side, you need to make sure the click is on the control or you could
end up with some funny results.
-- 
View this message in context: http://www.nabble.com/Generating-Mouse-Clicks-and-Keyboard-events-on-Mac-tp24484377p24593381.html
Sent from the Mono - OSX mailing list archive at Nabble.com.



More information about the Mono-osx mailing list