platform independent kbhit()

  • Thread starter Hans Georg Krauthaeuser
  • Start date
H

Hans Georg Krauthaeuser

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
 
S

Scott David Daniels

Hans said:
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
(e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top