Raise a Button_Click() event of another application

124 views Asked by At

This sounds implausible to me, but I just thought I'd ask.

There exists a .NET application with a button in it. I cannot edit this application source, its a pre-existing application.

I wish to, from my application, programatically raise the click event for that button.

Is this possible?

2

There are 2 answers

1
Limeoats On

The process would need to be running in order for it to perform an event, such as a button click. At that point, you have a few options for how to raise the button click event.

One way would be IPC (Inter-process Communication), using sockets or pipes between the two programs. You could also use shared memory if you prefer that option.

You would basically have to have the application with the button listening on a socket or pipe for a request to be sent. Once it is received, it can then call its own button click event from there.

The key is that both processes must be running and you must somehow send the other process a signal telling it to launch its button click event.

1
Stefano Altieri On

Mmmmmaybe..

Once upun a time there was an application named spy++. It allowed you to inspect a window and see properties, object names etc.

The spy++ has been ported to .net (see [enter link description here][1]

[1]: http://msdn.microsoft.com/en-us/magazine/cc163617.aspx). You can have a go.

If you rear the "Other ControlProxy Methods" section it states:

"There are a few additional methods worth taking a look at in ControlProxy. Call the SendMessage method to send a window message to the control. This is useful if you want to create a test harness. For example, you can send WM_CLICK or WM_KEYDOWN messages to simulate input".

Of course it is not an elegant nor stable approach :)