Search code examples
c#.netconsolekeystrokekeylogger

C# console get key stroke


Is there anyway for a C# console application to capture keystroke, including those that are pressed outside of the program, similar to a key logger? The one I found and tried is Console.ReadKey() but it can only read the keystroke sent to the console.


Solution

  • You need to use a low level keyboard hook. Here is an example using windows forms, but you can easily apply the same concept to a console application:

    http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx

    Hope it helps!