Is there any way in C# to create a simple keylogger? Thanks!
Printable View
Is there any way in C# to create a simple keylogger? Thanks!
what do you mean by keylogger ?
Paresh
Sorry about that, I was just wondering if there was a way to catch all the keystrokes that are going to other applications and log them without affecting the standard keyboard I/O. Basically, I'm trying to find out what happens to my computer when I'm not in my room.
Thanks!
You can catch keys pressed at any window focused and at any time. Here a way to do this via Windows API:Quote:
Originally posted by dosman711
...I was just wondering if there was a way to catch all the keystrokes that are going to other applications and log them without affecting the standard keyboard I/O. Basically, I'm trying to find out what happens to my computer when I'm not in my room.
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vKey);
And my own know-how to use above code:
public static int[] WhichKeysPressedNow()
{
System.Collections.ArrayList list =
new System.Collections.ArrayList();
for(int i = 0; i < 500; i++)
{
if (GetAsyncKeyState(i) != 0)
{
list.Add(i);
}
//list.Add((int)GetAsyncKeyState(i));
}
int[] res = new int[list.Count];
for(int i = 0; i < list.Count; i++)
{
res[i] = (int)list[i];
}
return res;
}
Now you can at any time see, which keys are pressed using my function "WhichKeysPressedNow". You can insert this function into an Timer code and check which keys are pressed each ... 20 ms. (this is faster than keys is possible to be pressed).
this can be done without using user32.dll.
however you will need to implement the key events. if you capture it properly then the game is on your side.
I agree that at some point user32.dll or some system native dll reference needs to be mentioned.
-Paresh