Capturing and sending keyboard / mouse input in C #

I'm looking for a way to send and receive keyboard information, no matter which application has focus. I remember in college I saw a presentation about the old Windows API, which allowed you to change the position of the cursor and send right clicks, etc.

Besides User32.dll, is there any way to do this using the .net framework?

+4
source share
2 answers

AFAIK, there is no way to capture GLOBAL keyboard and mouse events. But there are a few articles about CodeProject that demonstrate how to create wrappers for .NET classes for them.

You can check them out here:

1) Processing global mice and keyboard hooks in C #

2) Global mouse and keyboard library

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

+9
source

A few months ago, I used C # to create an application that reads wii nunchuck and moves the mouse. My first option was to use a class cursor to move the mouse, like this

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

Everything was fine, but it didn’t work when playing games, because they control the mouse differently, so in the end I used the Global Hooks that Kirtan mentioned here (+1). Based on my experience, I recommend you use Global Hooks.

+4
source

All Articles