Keyboard hook in linux

Michael Torrie torriem at
Sun Jan 13 17:42:01 CET 2013

On 01/13/2013 09:13 AM, K. Elo wrote:
> I am working on a small console app for linux. The idea is to display 
> some sensor values and the screen should update itself in, say, every 10 
> seconds.
> The user should have the possibly to change some configurations or gwt 
> help by pressing different keys (like you can do when running e.g. 
> 'top'). In other words: the program should NOT wait for the keypress (so 
> input() is not the solution), but simply capture keypresses and act 
> accordingly. If no key is pressed, the program should continue updating 
> the screen.

'top' is built using a programming library called 'curses' or 'ncurses.'
 That's likely where you'll need to go to.  At least if you want to be
able to run properly on different terminals.  ncurses handles terminal
output including writing text at certain positions, and input/output,
and even mouse interactions if you felt you needed that.  It's
apparently part of the standard python library:

More information about the Python-list mailing list