Reputation: 10824
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?
Upvotes: 5
Views: 23129
Reputation: 12025
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.
Upvotes: 4
Reputation: 21695
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 :)
Upvotes: 10