Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36739

Keyboard hook in linux

Date 2013-01-13 18:13 +0200
From "K. Elo" <maillists@nic.fi>
Subject Keyboard hook in linux
Newsgroups comp.lang.python
Message-ID <mailman.470.1358093620.2939.python-list@python.org> (permalink)

Show all headers | View raw


Hi!

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.

Practically I am looking for something similar than Pascal's 
"keypressed" function 
(http://www.freepascal.org/docs-html/rtl/crt/keypressed.html). The 
python code would be something like this:

--- snip ---

while True:
   if keypressed:
     ch=screen.getch()   # From 'curses'
     # Test, if 'ch' is a valid key
     # Do what the user want
   read_sensors()
   update_screen()

--- snip ---


I have searched in the Web and in several tutorials (e.g. "Programming 
python"), but this seems to be a tricky one. The 'pyHook' library seems 
to offer a keyboard hook manager, but 'pyHook' is not available for 
linux :( IMHO, the 'curses' library offers no (direct) solution to this...

Does anybody have an idea / a solution, how to capture keystrokes in linux?

Kind regards,
Kimmo

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Keyboard hook in linux "K. Elo" <maillists@nic.fi> - 2013-01-13 18:13 +0200
  Re: Keyboard hook in linux garabik-news-2005-05@kassiopeia.juls.savba.sk - 2013-01-13 18:11 +0000

csiph-web