[python-win32] Get key press in Windows 7
Tim Roberts
timr at probo.com
Fri Nov 28 07:44:36 CET 2014
On Nov 27, 2014, at 10:06 AM, John Sampson <jrs.idx at 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, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list