Huh. Works now.
import msvcrt
while True:
key = msvcrt.getch()
if key == 'h':
print 'Hello'
if key == 'b':
print 'Bye'
if key == '\r': # 'Enter' key
break
Dick
But here's a case where it seems I do need the
if msvcrt.kbhit() line
=========================
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
if msvcrt.kbhit():
key = msvcrt.getch()
if key == 'h':
print 'Hello'
if key == 'b':
print 'Bye'
if key == '\r': # Enter key
break
timeNow = time.time()
if timeNow - oldTimeNow > 5:
print "5 seconds passed"
oldTimeNow = timeNow
==========================
Without that line:
==========================
#!/usr/bin/env python
#coding=utf-8
import time
import msvcrt
timeNow = time.time()
oldTimeNow = timeNow
while True:
#if msvcrt.kbhit():
key = msvcrt.getch()
if key == 'h':
print 'Hello'
if key == 'b':
print 'Bye'
if key == '\r': # Enter key
break
timeNow = time.time()
if timeNow - oldTimeNow > 5:
print "5 seconds passed"
oldTimeNow = timeNow
============================
Without that line the "5 seconds passed" report is printed ONLY after
a "b" or an "h", not what I want.
Dick