KEYSCANNING within a LOOP, Newbie Question

This is a discussion on KEYSCANNING within a LOOP, Newbie Question within the C++ Programming forums, part of the General Programming Boards category; I have a for loop. If i use getch() or SCANf the program stops until I enter soemthing. Is there ...

  1. #1
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    Keyboard Scanning

    I have a for loop.

    If i use getch() or SCANf the program stops until I enter soemthing.

    Is there a function that can go inside a loop and the loop continues running until a specific key is pressed.
    i.e. like a menu system.

    Thanks

  2. #2
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    KEYSCANNING within a LOOP, Newbie Question

    I have a loop.

    If i use getch() or SCANf the program stops until I enter soemthing.

    Is there a function that can go inside a loop and the loop continues running past that keyscan function until a specific key is pressed.

    Just a keyword to get me started is ok, I will do the other work

    Thanks

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Ok, if you're using a windows based machine then you could look at _beginthread().
    zen

  4. #4
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    Its Borland

    No, Its Borland C++ for DOS.

    Do you understand the question though.

    1 Loop
    A few Keys Scanned until Pressed
    When pressed, the loop is exited.

    Look forward to the replys.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Try kbhit()
    It returns true if there is a character available to be read

  6. #6
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    Question

    Does it workwithin a loop or stick at that kbhit function until a key is pressed then continue with the program.

    It needs to be bypassed in the loop until the key is pressed.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    Code:
    while ( !kbhit() ) {
        // do stuff while we wait for a key
    }
    Man

  8. #8
    Registered User Robert_Ingleby's Avatar
    Join Date
    Oct 2001
    Posts
    57

    Thanks, But.........

    How do I implement a specific set of keys i.e. a,b,c,d and so forth for my menu system.

    As it stands this is only good for 1 keypress of ANY key whilst in the loop.

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    If kbhit has found a key, use getch() to retrieve it. If it is not the one you wanted, carry on with the program...
    Homer

    D'OH!

    mmmmmmmm... iterations

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie with Very Newbie Question
    By Jedi_Mediator in forum C++ Programming
    Replies: 18
    Last Post: 07-01-2008, 08:00 AM
  2. question about for loop
    By panfilero in forum C Programming
    Replies: 3
    Last Post: 09-27-2005, 05:59 AM
  3. Newbie Loop Question.
    By SlyMaelstrom in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2004, 03:47 PM
  4. newbie question: the for loop
    By Panopticon in forum C++ Programming
    Replies: 2
    Last Post: 01-10-2003, 02:25 AM
  5. Newbie question
    By uNreal in forum C++ Programming
    Replies: 3
    Last Post: 11-18-2002, 12:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21