How do I send mouse and keyboard events to another

2020-06-29 06:43发布

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 ?

3条回答
闹够了就滚
2楼-- · 2020-06-29 07:04

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

查看更多
叛逆
3楼-- · 2020-06-29 07:05

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.

查看更多
Viruses.
4楼-- · 2020-06-29 07:07

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)

查看更多
登录 后发表回答