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

[409 byte] By [mactacular] at [2007-12-23]
# 1

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.

DwayneNeed at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 2
I agree using SendInput from Win32 would work, but what I am looking for is for someway to do this without going into Win32 using WPF.
mactacular at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 3

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.

DwayneNeed at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 4
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.

mactacular at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 5

Have you considered UIAutomation:

http://blogs.msdn.com/abhinaba/archive/2006/06/27/648221.aspx

http://windowssdk.msdn.microsoft.com/en-us/library/system.windows.automation.aspx

It operates at a higher level than sending Input commands - works with Controls directly.

Sam

Sam at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 6
Yes, this is what I have decided on using. Especially since SendInput seems to take control away from the user. I don't think UIA will do everything I want it to do but it will help a lot.
Thanks
mactacular at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 7

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.

jddy at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...
# 8

You may want to have a look at Win32 function SetWindowsHookEx. I tried it in the past and it worked quite well.

- Abhijit

Abhi_N at 2007-8-30 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified