Hello!
I want to switch my script flow with condition of CTRL key pressed when i run it.
As i can understand, we can use msvcrt?
import sys
import msvcrt
from time import sleep
def sleep_sec(secstosleep, allowskip = True):
waitinterval_ms = 0.050
nwaits = int(secstosleep * 1000 / waitinterval)
sys.stdout.write("\n Sleeping for %s seconds. You can press CTRL-F12 to skip.\n\n" % secstosleep)
for sl in range(0, nwaits + 1):
sleep(waitinterval_ms)
if allowskip:
# Check if User has pressed CTRL-F12 to stop waiting
if = msvcrt.kbhit():
kp = msvcrt.getch()
if kp == '\xe0':
kp += msvcrt.getch()
if kp == '\xe0\x8a': # \x8a is the keycode for CTRL-F12
print "\a" # Beep once
sys.stdout.write("\nSleep interrupted by User\n")
break