#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    32
    Rep Power
    12

    Wait for the user input for a certain period of time...


    Is there a function in C++ to halt the program's input interval for a certain time period e.g. if the user doesn't input anything for 10 secs, they programs skips that portion and executes the rest of the statements....
    posted by: justujoo

    Error 13: BRAIN.SYS not responding, process terminted...!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    Depends entirely upon your OS/dev environment. Please post that first.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    32
    Rep Power
    12
    Windows Xp Professional, (DOS Mode), Visual C++ 6.0

    -- Note-- I don't know Win32 API programming...
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,592
    Rep Power
    4207
    1. #include <conio.h> and <time.h> into your code.

    2. Use the kbhit(), getch(), time() and difftime() functions like this:
    Code:
    time_t starttime, endtime;
    char ch;
    int done = 0;
    
    starttime = time();
    /* Poll for a keypress */
    while (!done) {
        if (kbhit()) {
            /* Get what key was pressed */
            ch = getch();
        }
    
        /* Check if 10 seconds have elapsed */
        endtime = time();
        if (difftime(endtime, starttime) > 10) 
            done = 1;
    }
    See http://msdn.microsoft.com/library/de...nreference.asp for documentation on these functions.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    32
    Rep Power
    12
    Kool, that's very easy...
    why didn't I come up with something this simple myself...

    Anyways thanks a lot...

IMN logo majestic logo threadwatch logo seochat tools logo