I want to end a while loop with a keypad stroke but for some reason the loop completely skips over the msvcrt part of the loop that would do that. Is there possibly a better way to do this without having to download any libraries?
Code:
import datetime
import time
import msvcrt
# import cv2
# from datetime import date, time
while True:
# if msvcrt.kbhit() and msvcrt.getch() == chr(27).encode():
# break
name = input('\n' + "What is your name?")
input('\n' + "Press any key to start the stopwatch")
startTime = datetime.datetime.now()
input('\n' + "Press any key to stop the stopwatch")
endTime = datetime.datetime.now()
time_out = ('\n' + "Time Out: " + str(endTime-startTime))
print(time_out)
student_out = ("Student Out: " + str(name))
print(student_out)
time_released = ("Time Released: " + str(startTime))
print(time_released)
time_back = ("Time Back: " + str(endTime))
print(time_back)
if msvcrt.kbhit() and msvcrt.getch() == chr(27).encode():
break