Wait for a keypress before continuing?

John Doe jdoe at usenetlove.invalid
Sun Aug 7 20:04:55 EDT 2011


My program does not need a prompt, it just needs to wait for any
key to be pressed before it continues. This is in Windows. 

  char=0
  while not char:
    char=msvcrt.getch()

That doesn't delay anything here.

  while 1:
    char=msvcrt.getch()
      break

That appears to put my program into an endless loop.

  while msvcrt.kbhit():
    sleep(4)
    msvcrt.getch()
  msvcrt.getch()

How can that not delay anything and then instantly get past the getch()?

  char=0
  while msvcrt.kbhit():
    sleep(4)
    msvcrt.getch()
  while not char:
    char=msvcrt.getch()

That doesn't delay anything.

Something seriously wrong with my system?


Thanks.



More information about the Python-list mailing list