I believe your problem is the use of repr() when assigning to c:

>>> u'\x1a'
u'\x1a'
>>> c = u'\x1a'
>>> c == u'\x1a'
True
>>> repr(c)
"u'\\x1a'"
>>> repr(c) == u'\x1a'
False
>>>


*Randy Syring*
Husband | Father | Redeemed Sinner

/"For what does it profit a man to gain the whole world
and forfeit his soul?" (Mark 8:36 ESV)/

On 11/27/2014 01:06 PM, John Sampson wrote:
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

_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32


_______________________________________________
python-win32 mailing list
python-win32@python.org
https://mail.python.org/mailman/listinfo/python-win32

Reply via email to