Keylogger

Hey all! So im trying to make a keylogger. So far this is what i came up with:
#include<iostream>
#include<windows.h>
#include<fstream>
#include<stdio.h>
using namespace std;
int main()
{ char ch;
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(Stealth,0);
}
fstream file;
file.open("getting.txt",ios::out|ios::app);
while(1)
{
cin.get(ch);
file<<ch;
}
file.close();
return 0;
}

But the problem is when i do type nothing gets entered in the file.

Please can anyone help?! I wanna do this for a school exhibition and its due in a week!! What should i change?
You can't use cin.get for this. http://msdn.microsoft.com/en-us/library/windows/desktop/gg153546(v=vs.85).aspx

I would use GetKeyState or GetAsyncKeyState.
So if I just replace cin . get with GetKeyState or the other one it will work? Also what's the difference between the two?
Last edited on
Because GetKeyState is based on your message queue, it also ignores keyboard input that was sent to another program. If the user switches to another program, any key presses that are sent to that program are ignored by GetKeyState. If you really want to know the immediate physical state of the keyboard, there is a function for that: GetAsyncKeyState. For most UI code, however, the correct function is GetKeyState.
Considering it is a keylogger you probably want GetAsyncKeyState

For more info: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx
Last edited on
So the basic difference is that the getasynckeystate gets the character the moment that the key is pressed and it also is not depended where you are typing? I get that.
Is there a way by which I can run this by just plugging in my
Removable pen drive? (not for my school project just wanna know)
I am a bit skeptical about this keylogger now... Anyways I am not sure if you can 100% "auto run" on windows 7 since it has that popup menu when ever I put in my flash drive. Though you could try adding the "auotorun.inf" file. http://www.samlogic.net/articles/autorun-usb-flash-drive.htm

It would probably be a pretty big security risk if programs could automatically open up and run without any user interaction and would pretty much be a virus.
Last edited on
Hmmm thanks. I've been programming on and off for a year. I know the basics it's just that i want to get a feel for the language .
And no I'm not hacking. I'm making this project to show people how easily they can be hacked, that's all.
closed account (z05DSL3A)
Thedevilstail wrote:
And no I'm not hacking. I'm making this project to show people how easily they can be hacked, that's all.
This is funny on so many levels.
So once I have a program running in the background, how do I stop it? :O
Anyone?
@Thedevilstail

Bring up 'Task Manager', and select the program in the Applications tab, you want stopped.
Grey Wolf wrote:
This is funny on so many levels.

Glad I wasn't the only one.
Thanks you guys
😊
when we talk about keylogging on windows, we talk about windows hooks.

look at it here - http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990%28v=vs.85%29.aspx

they can hook the whole system and can send your program system key strokes, mouse movements and lot more.

They are fun too.. so the system would send the key strokes to your program first and you can change them.. and the actual application which pressed the key will get something else..
Woah! Dude that's cool but I don't think I'll be able to finish it up by next week. But thanks a lot :)
Topic archived. No new replies allowed.