I am trying to use the ESCape key to go back to the Menu page and I can’t seem to implement it into an if statement. Once the ESCape key is pressed it should return to the main menu. I am using Python 3.7
import serial
import Keyboard
ser = serial.Serial ('COM18', baudrate = 115200, timeout = 1) #USB Serial Device
def getMenuData():
PhoenixMainMenu = ser.readline().decode('ascii')
return PhoenixMainMenu
def printScreen():
n=20
while n <= 20: #as long as
print(getMenuData())
n-=1
if n >= 0:
print (getMenuData())
n-=1
else:
break
while True:
print (printScreen())
print ('Escape Key brings you back to main menu')
UserInput = input('To access option type its coresponding number: ')
if UserInput == '1':
ser.write(b'1') #HW test
print ('first is the worst')
secondInput = input('To access the function type letter: ')
if secondInput == 'a':
ser.write(b'a')
else:
print ('Invalid entry. Please Try again.')
break
elif UserInput == keyboard.wait('esc')
ser.write(b'0x1b')
print ('Main MEnu')
print (printScreen())
break
else:
print ('Invalid entry. Please Try again.')