[Tutor] Linux library for getch() and kbhit()?

Bill Allen wallenpb at gmail.com
Thu Mar 17 16:46:31 CET 2011


Alan,

Ah ha, ungetch(), that is what I was needing.   I had be trying to simulate
kbhit() with getch() and keep being left with unhandled data in the buffer.
I had resorted to a trash=raw_input() to clear it.


Many thanks,
Bill





On Thu, Mar 17, 2011 at 04:01, Alan Gauld <alan.gauld at btinternet.com> wrote:

>
> "Bill Allen" <wallenpb at gmail.com> wrote
>
>
>  I have found that for the Windows build of Python the msvcrt library
>> provides getch() and kbhit() functions.   Is there a library available for
>> the Linux Python build that provides the same or similar functions?
>>
>
> curses.
>
> Take a look at the event handling topic in my tutor for examples
> comparing msvcrt and curses.
>
> I'm not sure if curses provides a kbhit() equivalent but you can
> usually simulate the effect by using a combination of getch()
> and ungetch() - not pretty but it works.
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110317/e3d55fc4/attachment.html>


More information about the Tutor mailing list