0

i need to perform the action done by using left mouse click when i press W for example:

i want to move the cruse to a folder and then press w so the folder open

i want to move the cruse to a file and press w and drag it and drop when i release w

i tried to use windowsFrom and performing the onKeyPress() and it calls onMouseDown() but of course it means that the onMouseDown() function will be called inside the form and what i need is a system behavior,,,, i am using windows 7 64 on VS2010 but i would like if it is some thing global for all windows

thanks a lot for helping,,,

  • 1
    possible duplicate of http://stackoverflow.com/questions/2416748/how-to-simulate-mouse-click-in-c – M.Babcock Feb 11 '12 at 16:17
  • 1
    If the actions you're trying to simulate are limited to things like opening a folder or file in Windows Explorer, then it would probably be best to just use `Process.Start` to open them. Otherwise, check out the answers to the related question I linked above, they should do the trick. – M.Babcock Feb 11 '12 at 16:29

2 Answers2

2

The first step you'll need to capture Key Down events in an external application is define a global hotkey:

I recommend checking out some of the answers for this question for a global hot-key: Best way to tackle global hotkey processing in c#? or this CodeProject article: A Simple C# Global Low Level Keyboard Hook

Then, as M. Babcock said you'll need to send the mouse-down events. The link he provided in the comment is a good one. I'm repeating it here for completeness.

How to simulate Mouse Click in C#?

If you actually need to send keyboard inputs, you can use InputSimulator which is something I have advocated (and used in the past) and it provides a very flexible (and reliable) wrapper that is capable of simulating keyboard events.

It wraps SendInput under the hood but abstracts away all the PInvoke calls and other complexity.

InputSimulator.SimulateKeyDown(VirtualKeyCode.CTRL);
InputSimulator.SimulateKeyPress(VirtualKeyCode.KEYS_V);
InputSimulator.SimulateKeyUp(VirtualKeyCode.CTRL);

or

InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C); 
Community
  • 1
  • 1
robowahoo
  • 1,259
  • 9
  • 10
0

Use a boolean flag for the clicking, and set it on both by clicking or pressing your hotkey. For instance, this flag should be declared inside the form, and the events KeyDown and MouseDown set it true, while KeyUp and MouseUp set it false. For all your actions now you use this flag for verifying the click. (Not sure if it would works in Windows app, in XNA it works fine). For using outside the class, just set this flag as a public property.

Mephy
  • 1
  • 1