Keyboard input/Keypress check: Difference between revisions

m
m (added whitespace before the TOC (table of contents), added other whitespace to the task's preamble.)
Line 366:
<lang python>#!/usr/bin/env python
 
import thread__future__
# this solution will work only in Windows, as msvcrt is a Windows only package
import sys
 
if sys.version_info.major < 3:
import thread
import thread as _thread
else:
import _thread
import time
 
Line 376 ⟶ 379:
except ImportError:
def getch(): # define non-Windows version
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
Line 392 ⟶ 395:
char = getch()
 
thread_thread.start_new_thread(keypress, ())
 
while True:
if char is not None:
print ("Key pressed is " + char.decode('utf-8'))
break
print ("Program is running")
time.sleep(5)</lang>