Monitoring keyboard activity in C# while my application is in the background

Tane Lattanzio picture Tane Lattanzio · Apr 30, 2012 · Viewed 15.8k times · Source

First of all I need to make it clear that I have no interest in keylogging.

I need a way to monitor keyboard activity at the most basic level while my application is in the background. I don't need to know which keys, I don't need to save any data, I don't need or plan to hide my application at all, all I need is to know when keys are pressed and invoke a method.

I'm looking for the simplest way to do this possible, I know a reasonable amount of C# but nothing too complex as most of my knowledge is self-taught.

I've looked around for some appropriate ways of doing this and I've found nothing useful. All I've found is a bunch of people saying "No, that's illegal" on forums and source code for in depth keyloggers.

If any of you could advise me on a way to achieve this then I would be most appreciative.

Answer

Mesh picture Mesh · Apr 30, 2012

You'll need to use Window Hooks:

Low-Level Keyboard Hook in C#

But beware, Windows security, may be protecting us from doing what you want!