platform independent kbhit()

Discussion in 'Python' started by Hans Georg Krauthaeuser, Jan 17, 2005.

  1. Hey all,

    this is probably a FAQ, but I didn't found the answer...

    I use msvcrt.kbhit() to check for a user keyboard event on windows. But
    now, I would prefer to make the module independent from the platform
    used. I already know that I can use curses (on linux/unix) or Tkinter.
    Also, I found this http://my.execpc.com/~geezer/software/kbhit.c C
    source that has a kbhit() and a getch() for linux/unix that I can SWIG
    to python.

    Are there other (more simple, pure python, true platform independent)
    possibilities?

    Best regards
    Hans Georg Krauthaeuser
    --
    www.uni-magdeburg.de/krauthae
    Hans Georg Krauthaeuser, Jan 17, 2005
    #1
    1. Advertising

  2. Hans Georg Krauthaeuser wrote:
    > I use msvcrt.kbhit() to check for a user keyboard event on windows. But
    > now, I would prefer to make the module independent from the platform
    > used.

    This is not in general possible; many machines do not have keyboards.
    You can, perhaps, build one for yourself from a pair of implementations
    or more. Portable software seldom comes from adding one platform at a
    time that the software works on. Portable software comes from working
    using only features common (or in rare circumstances available) on all
    machines in your target set, and then adding enough tests to believe
    the portability. CPython starts with the C89-supported environment as
    its base. It tries hard to stick to that abstract machine. I assume
    Jython does a similar thing using Java VM semantics that it trusts will
    be common across implementations.

    > I already know that I can use curses (on linux/unix) or Tkinter.
    > Also, I found this http://my.execpc.com/~geezer/software/kbhit.c C
    > source that has a kbhit() and a getch() for linux/unix that I can SWIG
    > to python.

    Either of these might be a good basis for your personal "all machines I
    care about" semantics. If you use curses, make sure it doesn't impose
    an extra constraint on all terminal access.

    --Scott David Daniels
    Scott David Daniels, Jan 17, 2005
    #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. Rasmus B. Nielsen

    kbhit in console?

    Rasmus B. Nielsen, Aug 28, 2003, in forum: Java
    Replies:
    1
    Views:
    2,412
    Harald Hein
    Aug 29, 2003
  2. DevarajA

    something like kbhit

    DevarajA, Jun 9, 2005, in forum: C++
    Replies:
    8
    Views:
    3,736
    Alan Johnson
    Jun 10, 2005
  3. Replies:
    0
    Views:
    955
  4. hugo27

    How, exactly, does kbhit( ) work?

    hugo27, Jun 28, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,769
    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,526
    Chris Croughton
    Apr 12, 2005
Loading...

Share This Page