Keyboard hook in linux

K. Elo maillists at nic.fi
Sun Jan 13 13:10:46 EST 2013


Hi!

Thanks, Michael, for your quick - and heplful - reply.

13.01.2013 18:46, Michael Torrie wrote:
> You're wrong.  curses does offer a direct solution to this.  Check the
> docs.  Also here's a nice intro document for Python 3:
> http://docs.python.org/dev/howto/curses.html

You are right :) The docs tell us (I somehow missed this when reading 
the doc last time):

"It’s possible to change this behavior with the method nodelay(). After 
nodelay(1), getch() for the window becomes non-blocking and returns 
curses.ERR (a value of -1) when no input is ready. There’s also a 
halfdelay() function, which can be used to (in effect) set a timer on 
each getch(); if no input becomes available within a specified delay 
(measured in tenths of a second), curses raises an exception."

This is actually funny: if you google for e.g. "capture keystrokes 
python", you will find masses of suggestions, none of them having this 
simple and elegant (i.e. python-like :) ) solution included.

Now it works and my problem is solved. Thank you!

Kind regards,
Kimmo




More information about the Python-list mailing list