View Poll Results: What is the best programming language?

Voters
1. You may not vote on this poll
  • C/C++

    1 100.00%
  • Java

    0 0%
  • COBOL

    0 0%
  • Basic

    0 0%
  • Other

    0 0%

Thread: Passive Keyboard Input

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    Passive Keyboard Input

    I have used cin to get keyboard input for variables, getch() for getting single keypress information, but all of those cause the computer to wait for a keypress. I would like to have some kind of getch() like function that not "pause" the program. I would find this very useful for real-time DOS games.

    -Zagaberoo

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    If your compiler supports it, you may be able to use the kbhit function.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    kbhit?

    what is kbhit? what header does it require? how is it used?

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    kbhit() question

    kbhit() is a nifty little function, but can you make it useful, like getch()? I would really like to make a real-time game and need some kind of passive keyboard input that does not "pause" my program. kbhit() is cool, but can you have it input to a char or string? If not, what function or other helpful thingy can I use?

    ***PROGRAM IS IN DOS***

    -Zagaberoo
    I am the Uber Noob

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Pointless poll closed, and threads merged
    Try to be more careful when posting

    It goes like this
    Code:
    // key pressed?
    if ( kbhit() ) {
      ch = getch();  // yes, read it
      msg[n++] = ch;
      msg[n] = '\0';  // add to line so far
      if ( ch == '\r' ) {  // end of line?
        process(msg);  // yes, figure out what it means
        n = 0;
      }
    }
    // do stuff which can't wait
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    There is no portable way to do it. You have to rely on compiler-specific code. What compiler are you using?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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. Need help with Console Keyboard Input
    By pawelx2 in forum Game Programming
    Replies: 5
    Last Post: 05-30-2002, 11:03 PM