tags:

views:

187

answers:

3

Let's assume that we've got 2 windows processes ,

Process A is the sender, and Process B is the receiver.

Process B is running a classic Win32 API events loop

How do I generate and send mouse and keyboard events from process A to B ?

+4  A: 

Basically via SendMessage or PostMessage. If you want to simulate input events for the whole operating system, then SendInput might be interesting.

Michael
might I ask for a short example?
Maciek
+1  A: 

You may want to check TestAPI in Codeplex it includes some C# classes that wrap SendMessage and PostMessage APIs (http://testapi.codeplex.com/SourceControl/changeset/view/35517#424245)

CriGoT
+1  A: 

TestApi actually wraps up SendInput internally, and exposes a couple of simple classes -- Mouse and Keyboard -- to help you simulate input. SendInput provides the most general way to inject input, but is a notoriously tricky API to use -- the wrappers simplify the usage greatly.

See http://blogs.msdn.com/b/ivo_manolov/archive/2008/12/15/9223397.aspx for specific usage examples.

Ivo Manolov