Thread: FAQ Keyboard Input ? (C++)

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

    Question Keyboard Input ?

    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
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    use kbhit ()... kbhit () checks the keyboard buffer if there's an available keystroke and getch () returns it... if no keystrokes exist, getch () waits until you press something into the keyboard buffer and retrieves it...

    so, check if a keystroke exists and return it with getch (), if it is not available, don't return getch () and return zero [or some other flag value]... any ?uestions?

    -hth
    hasafraggin shizigishin oppashigger...

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

    Thumbs up Awesome, thanks man

    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
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    only problem with kbhit() is that it is not part of either the c or c++ standards therefore not all compilers have this facility.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    oh... well good anyway... coindentally i use the interrupt so i can get the ASCII and scan codes both... but what is the standardized alternative then SC? thank you!
    hasafraggin shizigishin oppashigger...

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Unfortuneately there isn't one DA. This is because it is highly operating system specific. In dos as you know you use interrupts.In windows you use GetAsyncKeyState().In linux/unix you use ____________ (salem please fill in the blank!) .Sorry I'm a windows guy!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    i would have thought the protocols for such a thing were more closely tied to the hw...

    speaking of which, all software does use hw interrupts? right? i'm pretty sure... else what links the hw to the sw? hmmm.
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with keyboard input
    By fighter92 in forum Game Programming
    Replies: 6
    Last Post: 03-20-2009, 09:41 AM
  2. faq: cached input with mygetch()
    By ichijoji in forum Linux Programming
    Replies: 4
    Last Post: 06-18-2008, 11:36 PM
  3. Using low-level keyboard for input
    By hdragon in forum C++ Programming
    Replies: 25
    Last Post: 12-24-2007, 02:13 PM
  4. Stealing Keyboard input
    By zort15 in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2007, 02:22 PM
  5. Keyboard Input
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-29-2002, 11:41 AM