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 ?
Basically via SendMessage
or PostMessage
. If you want to simulate input events for the whole operating system, then SendInput
might be interesting.
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)
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 Link for specific usage examples.
精彩评论