Capture and send keyboard / mouse input in C#

2020-02-09 22:33发布

I am looking for a way to send and receive keyboard information regardless of what app has focus. I remember back in College seeing a presentation about an old Windows API that let you change the cursor position and send right clicks and such.

Besides User32.dll is there a way to do this with the .net framework?

2条回答
The star\"
2楼-- · 2020-02-09 23:13

Some months ago, I used C# to create an app that read from a wii nunchuck and move the mouse. My first option was to use the cursor Class to move the mouse like this

Cursor.Position = new Point(Cursor.Position.X + 10, Cursor.Position.Y + 10);

All was fine, but did't work when playing games because they manage the mouse in a different way, so at the end I used the Global Hooks that Kirtan mentioned here (+1). Based in my experience, I recomend you to use Global Hooks.

查看更多
▲ chillily
3楼-- · 2020-02-09 23:36

AFAIK, there's no way to capture the GLOBAL keyboard & mouse events. But there are a few articles on CodeProject which demonstrate the creation of .NET class wrappers for the same.

You can check them out here:

1) Processing Global Mouse and Keyboard Hooks in C#

2) Global Mouse and Keyboard Library

EDIT: BTW, I had created a SMALL keylogger in C# using the 1st library :)

查看更多
登录 后发表回答