Reading Keyboard Scan Codes

Bjorn Pettersen BPettersen at NAREX.com
Wed Jul 23 18:29:56 EDT 2003


> From: François Pinard [mailto:pinard at iro.umontreal.ca] 
> 
> [Michael Bendzick]
> 
> > Is there a simple way in python to read a keyboard scan 
> > code?  I'm working on a shell script that interfaces 
> > with a proprietary keyboard device (extra buttons) and 
> > need to be able to distinguish between those keys.
> 
> Within Linux in console mode, you merely do:

[...]

> However, I do not know if reading scan codes or key codes is 
> easily done within X, nor on MS-Windows.  I would like finding or 
> discovering recipes in this area.  So, please share your tricks 
> in this area, if any! :-)
[...]

I'm assuming you can use the msvcrt module:

>>> def getch():
...     import msvcrt
...     while not msvcrt.kbhit(): pass
...     return msvcrt.getch()
...
>>> getch()
'a'
>>>

-- bjorn





More information about the Python-list mailing list