Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'say,': 0.05; 'test,': 0.05; '(so': 0.07; 'python': 0.09; 'linux.': 0.09; 'pressing': 0.09; 'solution,': 0.09; 'accordingly.': 0.13; 'library': 0.15; '(like': 0.15; 'tutorials': 0.15; '"programming': 0.16; 'keypress': 0.16; 'received:fi': 0.16; 'seconds.': 0.16; 'true:': 0.16; 'url:html)': 0.16; 'app': 0.19; 'keyboard': 0.22; 'keys': 0.22; 'this:': 0.23; 'seems': 0.23; 'idea': 0.24; 'linux': 0.24; 'header:User-Agent:1': 0.26; '---': 0.26; 'values': 0.26; '(e.g.': 0.27; 'possibly': 0.27; 'updating': 0.27; 'e.g.': 0.30; 'function': 0.30; 'code': 0.31; 'anybody': 0.32; 'running': 0.32; 'to:addr:python-list': 0.33; 'screen': 0.34; 'continue': 0.35; 'similar': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'display': 0.36; 'itself': 0.37; 'does': 0.37; 'some': 0.38; 'several': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'help': 0.40; 'skip:u 10': 0.60; 'kind': 0.61; 'received:62': 0.62; 'different': 0.63; 'offer': 0.65; '(direct)': 0.84; 'gwt': 0.84; 'keystrokes': 0.84; 'this...': 0.84; 'tricky': 0.91 Date: Sun, 13 Jan 2013 18:13:28 +0200 From: "K. Elo" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Keyboard hook in linux Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358093620 news.xs4all.nl 6902 [2001:888:2000:d::a6]:36632 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36739 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