Thread: Keyboard input ?

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    Question Keyboard input ?

    Prolly not a difficult question, but I'm making a text/ASCII graphic game and there are times where I need to "Cancel input" from the keyboard to allow the user to watch something happen. Where if you hit enter 3 times during it and enter takes you out of the screen at the end you are taken out because I use the getch() command to input. Is there any way to temporarily cease input from the keyboard if using the getch() command? Thanks guys.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Hmm

    Not sure what you mean... Something like this?


    int main()
    {
    char Input=0;
    while(Input!=27) //Loop while ESC is not pressed
    {
    Input=0;
    if(kbhit()) Input=getch(); //Get Keyboard input if a button is pressed

    //Whatever code you want...

    }
    return 0;
    }


    (I haven't tested the code, it might have some bugs )
    Last edited by Magos; 11-06-2001 at 01:31 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    Thumbs up Thanks a lot

    Hey man, thanks for that advice, it worked! I'm not a very good programmer yet but that command will come in handy =). Thanks again!

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Another

    You can also download another keyboard handler routine from this site: http://shd.cjb.net/
    (Press the icon under the speaker)

    It's harder to understand, but it lets you press multiple keys at once (great in games).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    16

    stopping input

    I was wondering the same thing myself sort of. I need a way to stop all input... Nothing is to get through to the keyboard input buffer thing... And i dont wanna use getchar to stop all but enter... isnt there some ignore_input thing out there... and don't even try that fflush(stdin); thing, that doesnt apply here.
    "Practice means good, Perfect Practice means Perfect"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help using inline assembly for keyboard input
    By sleventeen in forum C Programming
    Replies: 7
    Last Post: 05-10-2009, 01:31 AM
  2. Keyboard Input
    By CaliJoe in forum C++ Programming
    Replies: 3
    Last Post: 05-08-2009, 09:51 AM
  3. Keyboard input in a Dialog
    By ksarkar in forum C++ Programming
    Replies: 1
    Last Post: 05-20-2005, 05:39 AM
  4. Intercepting keyboard input
    By EvBladeRunnervE in forum Windows Programming
    Replies: 3
    Last Post: 01-08-2004, 09:03 AM
  5. FAQ Keyboard Input ? (C++)
    By Malikive in forum FAQ Board
    Replies: 6
    Last Post: 11-07-2001, 09:30 PM