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. Advertisements

  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. Advertisements

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. ibeetb
    Replies:
    1
    Views:
    544
    Steve C. Orr [MVP, MCSD]
    Jun 1, 2004
  2. Harald Hein
    Replies:
    9
    Views:
    598
    Andrew Thompson
    Aug 17, 2003
  3. RA Scheltema
    Replies:
    10
    Views:
    686
    Joona I Palaste
    Jan 24, 2004
  4. RA Scheltema

    platform independent serialization of a long

    RA Scheltema, Jan 23, 2004, in forum: C Programming
    Replies:
    10
    Views:
    691
    Joona I Palaste
    Jan 24, 2004
  5. MK
    Replies:
    1
    Views:
    958
    Peter Hansen
    Jun 25, 2003
  6. Gandalf
    Replies:
    1
    Views:
    412
    Lawrence Oluyede
    Aug 18, 2004
  7. Steven Knight
    Replies:
    0
    Views:
    1,440
    Steven Knight
    Aug 18, 2004
  8. morphex
    Replies:
    2
    Views:
    426
    Gustavo Rahal
    Feb 21, 2005
Loading...