I need to capture everything that I type on my keyboard and then store it in numerous ways. I\'d prefer it to be written in C# for .Net, but anything will do really. My reas
Old question but...
In Windows you can use the APIs of the user32.dll.
For a very simple keylogger you can use the method GetAsyncKeyState() checking whether each character of the ASCII table is pressed.
The whole code for a very simple and stupid keylogger written in a Console Application would be:
[DllImport("user32.dll")]
public static extern int GetAsyncKeyState(Int32 i);
static void Main(string[] args)
{
while (true)
{
Thread.Sleep(100);
for (int i = 0; i < 255; i++)
{
int keyState = GetAsyncKeyState(i);
if (keyState == 1 || keyState == -32767)
{
Console.WriteLine((Keys)i);
break;
}
}
}
For those who are looking for something more robust and cleaner I've created an API that makes it easy. You only need to do this:
api.CreateKeyboardHook((character) => { Console.Write(character); });
More details here: https://github.com/fabriciorissetto/KeystrokeAPI