tags:

views:

50

answers:

4

i want to fire automatic key press or mouse click event when a color appears on the screen on other application or Browser....

A: 

I'm not 100% sure what you want, but if all you are after is running the method linked the the button.Clicked event, then you can manually run the method just like any other method.

Øyvind Bråthen
A: 

You can use the .NET SendKeys class to send keystrokes. Emulating mouse clicks requires P/Invoke. I don't know how to detect colors on the screen.

Mike Clark
+1  A: 

It depends a lot on what you want. Do you want to send the keys to

  • your Application
  • another fixed Application
  • Simulate a global keypress

SendKeys Sends Messages to the active app. But you have a problem if you're targeting a specific application and the active window changes.

keybd_event is very low level and injects a global keypress. In most cases SendKeys is preferred. For simulation mouse input you can use mouse_event

When working with a fixed target window, sending it messages can work depending on how the window works. But since this doesn't update all states it might not always work. But you don't have a race condition with changing window focus, which is worth a lot.

So my recommendation is when targeting a specific window/application try using messages first, and only if that fails try one of the lower level solutions.

CodeInChaos
A: 

You can use WM_COMMAND for example in your case you can use WM_LBUTTONUP command, for sending mouse up command. see this for example. you should set the window which is a receiver of command you can set it as null (0 in VC) to set it as Desktop. the command will be sent to MSMQ, now in WndProc of other application you should process it. Code is in VC

override virtual void Form1::WndProc(System::Windows::Forms::Message %m)
{
  if (m.Msg == WM_LBUTTONUP)
  {
     if (m.LParam == x) // x is a value you set it.
     {
        DoAction();
     }
  }
}
SaeedAlg