kbhit in console?

Discussion in 'Java' started by Rasmus B. Nielsen, Aug 28, 2003.

  1. hi

    Can any tell me how/if I can do something like (in C) kbhit, in the console?


    From Rasmus B. Nielsen
    Rasmus B. Nielsen, Aug 28, 2003
    #1
    1. Advertising

  2. Rasmus B. Nielsen

    Harald Hein Guest

    "Rasmus B. Nielsen" wrote:

    > Can any tell me how/if I can do something like (in C) kbhit, in
    > the console?


    You can't with pure Java, and you shouldn't.

    kbhit is not a standard C function but some operating system specific
    extension. It's principle model is based on wasting CPU cycles in loops
    like

    while(!kbhit()) {
    ;
    }

    This is desastrous on any timesharing operating system and should be
    avoided at all cost. Java doesn't have any equivalent, and Java is in
    general very weak when it comes to deal with the console.

    You can create a GUI doing this things but in a more efficient way. You
    subscribe to keyboard events, and whenever a key is pressed, your code
    is called. When no key is pressed, the VM and the OS can do other
    important things instead of burning CPU cycles.
    Harald Hein, Aug 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DevarajA

    something like kbhit

    DevarajA, Jun 9, 2005, in forum: C++
    Replies:
    8
    Views:
    3,743
    Alan Johnson
    Jun 10, 2005
  2. Replies:
    0
    Views:
    966
  3. Hans Georg Krauthaeuser

    platform independent kbhit()

    Hans Georg Krauthaeuser, Jan 17, 2005, in forum: Python
    Replies:
    1
    Views:
    982
    Scott David Daniels
    Jan 17, 2005
  4. hugo27

    How, exactly, does kbhit( ) work?

    hugo27, Jun 28, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,784
    Dan Pop
    Jul 5, 2004
  5. exquisitus

    'nix equivalent of Dos function kbhit() ?

    exquisitus, Apr 11, 2005, in forum: C Programming
    Replies:
    6
    Views:
    1,534
    Chris Croughton
    Apr 12, 2005
Loading...

Share This Page