Write Your Own Keylogger for Windows in C++

For those who don’t know what a keylogger is, See this link.

I found out the pieces scattered over the web and this is a small effort to understand keyloggers better and write one from the scratch on your own.

Warning: This tutorial is for educational purpose only, I am not responsible for any misuse.


You need an IDE for writing / compiling programs in C++. I am assuming, you are using a windows machine.

1. Download the code blocks IDE for C++ with mingw support(codeblocks-10.05mingw-setup.exe) from here

2. Double click on the setup file and keep on pressing ‘next’ till the installation completes.

3. Launch code blocks IDE, When you first start it, it might ask you to choose the debugger, select the default one and proceed.

4. Now, Once the IDE launches, Select File -> New-> Project.

5. This will show you a grid of categories, Select 'Console Application’, Hit 'next’, select 'C++’ as environment and then hit 'next’.

6. Enter project title, path and project file name say 'KL’. Now, click 'next’ and then hit 'finish’.

7. On the left pane, navigate to 'main.cpp’ file under 'Sources’ directory.

8. In the main.cpp, copy the following code(I have commented the code for better understanding, If you can’t, google it)

9. 'Build and Run’ the main.cpp. This will automatically start the keylogger in stealth mode on your PC and store the keystrokes in the directory path you mentioned as an argument for save() function, To end the monitoring, goto task manager and kill the process with name of your project title.

10. Now, close the code blocks IDE and goto the workspace project-title/bin/Debug

11. Here, you’ll find an .exe file with the name same as your project-title. This is your final keylogger executable.


- Adding email support to email the keystroke log periodically.

- Decreasing the AV detection ratio (right now, its 4/43) by using few more tacts.

*Have fun and Use with responsibility, guys :D