On Nov 27, 2014, at 10:06 AM, John Sampson <jrs....@ntlworld.com> 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’

Right, because that’s the ASCII value for Ctrl-Z.


> While it appears in the console as above, if it is assigned to a 
> variable ( c = repr(readchar.readkey()) )

In this line, “readchar.readkey()” returns a string of length 1.  It contains 
one character, with a value of 1A in hex.  When you pass that through “repr”, 
you end up with a string of length 7: “u”, apostrophe, backslash, “x”, “1”, 
“a”, and apostrophe.  Naturally, when you compare that to a string of length 1, 
it doesn’t match.


> This does not make sense. What type of object is a keystroke?

It’s a string containing one character.  Wasn’t that obvious from your output?
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

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

Reply via email to