On Oct 29, 4:26 am, Dick Moores <[EMAIL PROTECTED]> wrote: > Windows XP Pro, Python 2.5.1 > > import msvcrt > while True: > if msvcrt.kbhit(): > key = msvcrt.getch() > if key == 'Enter' > do something > > Is there a way to catch the pressing of the 'Enter' key? > > Thanks, > > Dick Moores
Let's find out: >>> from msvcrt import getch >>> while True: ... key = getch() ... if key: print repr(key)+',', ... 'p', 'r', 'e', 's', 's', 'i', 'n', 'g', ' ', 'e', 'n', 't', 'e', 'r', ':', ' ', '\r', Gee, I pressed enter, and it returned '\r'. I wonder... >>> import msvcrt >>> while True: ... if msvcrt.kbhit(): ... key = msvcrt.getch() ... if key == '\r': ... print "success!" ... success! -- http://mail.python.org/mailman/listinfo/python-list