[Tutor] how does one poll the keyboard?

Jeff Shannon jeff@ccvcorp.com
Fri, 23 Nov 2001 15:05:17 -0800


> On Fri, 23 Nov 2001 12:08:32 -0500,
> Andrei Kulakov <sill@optonline.net> wrote:
>
> 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.
> >   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.

Actually, it *has* a keywords system, at least the online version...

http://www.python.org/cgi-bin/faqw.py

Searching for "keyboard polling" with the "Keywords (any)" option selected, selected, pulled up two FAQ items, one of which was pertinent (i.e., use the msvcrt module for kbhit() and getch() functions).

Also, the ActiveState distribution comes with the help as a .chm file, which is fully indexed and searchable by keywords.  This may or may not be available separately, I'm not sure... but it is *very* useful!  :)

Jeff Shannon
Technician/Programmer
Credit International