[python-win32] Get key press in Windows 7

John Sampson jrs.idx at ntlworld.com
Thu Nov 27 21:30:20 CET 2014


Many thanks - by excluding repr the code behaves in a comprehensible 
way. The example code that was provided at Stack Overflow included repr 
so I assumed that it was necessary for some reason.
If I were allowed to comment there I would ask why.

Regards

John Sampson

On 27/11/2014 18:26, Randy Syring wrote:
> 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 at python.org
>> https://mail.python.org/mailman/listinfo/python-win32
>>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20141127/643680e9/attachment.html>


More information about the python-win32 mailing list