[Tutor] how does one poll the keyboard?

Andrei Kulakov ak@silmarill.org
Fri, 23 Nov 2001 12:08:32 -0500


On Fri, Nov 23, 2001 at 11:37:09AM -0500, tonycervone wrote:
>  How does one poll the keyboard with Python to see if a specific key( that I choose to define as the key to press) has been pressed while a program is running?  I guess the script would poll the keyboard and run in the background of a main program.Of course, the script could not have an indefinite loop so as to prevent the program from running. The program will then quickly run the script and if the key has been pressed a message will appear that such a key has been pressed. 
> thanks.
> PS. I have now most books on Python; yet I still feel that the indices are not comprehensive enough for novices.  I know that this is a general statement, but for this particular question , for example, I could not find anything in the back of the books. the books are: The quick Python Book, Python Standard Library, learn to Program using Python, and the big Core Python Programming. Considering the number of pages( a lot), they all seem to lack easy and comprehensive indices. The examples in the books, too, have very small type and assume some intuition about how Python works . This is not meant as a criticism, but constructive observations that should help authors who want to reach a wider general want to be audience. The folks are among the best, most knowlegeable and kind helpers I have found. So keep up the good work.
> 
> 
>   tony

This is in the FAQ -
http://www.python.org/cgi-bin/faqw.py?req=edit&file=faq04.074.htp

Not that I blame you for not finding it - I had to ask on a newsgroup,
too.. I think faq needs some sort of keywords system - even though I
remembered this entry it took me a few tries to hit on the right search
words to find it.

To keep it from blocking, use threads or select module.

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org