[python-win32] Get key press in Windows 7

John Sampson jrs.idx at ntlworld.com
Thu Nov 27 19:06:24 CET 2014


I have tried a module called readchar to make a Python 2.7 script detect 
keystrokes in Windows 7.
I found it via a link from Stack Overflow.
When <ctrl>z  is pressed its output is printed in the console as
u'\x1a'
According to Python 2.7 its type is 'str'. Seeing that it is preceded by 
a 'u', why is it not 'unicode'?
While it appears in the console as above, if it is assigned to a 
variable ( c = repr(readchar.readkey()) )
and then the value of the variable is tested:
print c == u'\x1a'
the answer is 'False'
This does not make sense. What type of object is a keystroke?

Perhaps I need to find some other way for a Python script detect 
keystrokes but I am confused as to what Python sees them as.

Any advice would be welcome.

Regards

John Sampson



More information about the python-win32 mailing list