Capture and send keyboard / mouse input in C#

旧城冷巷雨未停 提交于 2019-11-27 16:56:38

问题


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?


回答1:


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 :)




回答2:


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.



来源:https://stackoverflow.com/questions/1112949/capture-and-send-keyboard-mouse-input-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!