On 2/20/2010 5:52 AM, Paul Whittaker wrote:

Using the following script, the (Windows 7) PC echoes the key presses but doesn't quit (ever!)

import msvcrt

print('Press SPACE to stop...')

while True:

    k = msvcrt.getch()     # Strangely, this echoes to the IDLE window

    if k == ' ':           # Not recognized

        break



According to the docs: "msvcrt.getch() - Read a keypress and return the resulting character....This call will block if a keypress is not already available, but will not wait for Enter to be pressed. If the pressed key was a special function key, this will return '\000' or '\xe0'; the next call will return the keycode. The Control-C keypress cannot be read with this function."

IOW - getch always returns 1 character.

You are testing for a 0 length string. Will never happen.

What keystroke do you want to break the loop?

--
Bob Gailer
919-636-4239
Chapel Hill NC

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to