emulating a mouse in WPF
Hi,
I am trying to emulate a real mousedevice and its behaviour (left click,right click, mouse enter, mouse leave etc) by creating a custom control for it. So far I have not been able to figure out how to implement this. If any one has any experience in this please advice, how I could go about creating this or maybe an altogether different idea for achieving the same would be really appreciated.
Thanks
The correct way to emulate a mouse is to use the SendInput() method available in the Win32 API. This method will make the mouse work everywhere (across all applications on the desktop), and is mostly indistinguishable from real mouse input.
Your options are fairly limited. The crux of the problem you will face is that the various mouse input event args don't carry much data. Instead the data is fetched on demand. For example, assume you receive a mouse event args and the LeftButton property says "pressed". If you stash away a reference to the event args and look at it again at some point in the future, the LeftButton property may no longer have a value of "pressed". This is a great feature, and is diminishes the chances of security problems like replay attacks and spoofed input. But you are essentually asking to spoof input, so this feature is going to get in your way.
You could define your own event args, but then no existing controls will know what to do with them.
Thanks, I guess I might have to use SendInput. I am working on designing and implementing an application which will record all user input on a third application (also ours) and then replay them automatically. My only concern is that using SendInput should not take away control from the real mouse, in the sense that I want the user to have full control over the real mouse and keyboard, but at the same time be able to replay the recorded action using SendInput or any other method.
The other option is to use RoutedCommands and define my own Gestures which, but that would require a lot of modification to the Recorded Application, and so is not very viable.
I had looked for a method emulating mouse actions in WPF for a long time, but at last, I have to use win32 method SendInput().
I'm wondering why they don't provide a method for emulating click while System.Windows.Forms.Cursor.Position is provided for emulating move mouse.