By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

platform independent kbhit()

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Sc***********@Acm.Org
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.