The program I wrote is meant to be a menu navigable through live keyboard inputs with the keyboard module; unlike standard menus created in python which are navigated through set user inputs (input()) this menu should have a scroll like affect when using it. Code:
def MenuInterface():
import keyboard
MenuList = ["""Welcome to Empires Shell
> [PLAY]
[HELP]
[CREDITS]
[EXIT]
""", """Welcome to Empires Shell
[PLAY]
> [HELP]
[CREDITS]
[EXIT]""", """Welcome to Empires Shell
[PLAY]
[HELP]
> [CREDITS]
[EXIT]
""", """Welcome to Empires Shell
[PLAY]
[HELP]
[CREDITS]
> [EXIT]
"""]
print (MenuList[0])
x = 0
while True: #This is the actual loop where I'm encountering my error
if keyboard.read_key() == "s":
x = x + 1
if x == -1:
x = 3
print (MenuList[x])
elif x == 4:
x = 0
print (MenuList[x])
else:
print (MenuList[x])
MenuInterface()
Running Returns:
Welcome to Empires Shell
> [PLAY]
[HELP]
[CREDITS]
[EXIT]
After typing "s" into the shell, returns:
Welcome to Empires Shell
[PLAY]
> [HELP]
[CREDITS]
[EXIT]
Welcome to Empires Shell
[PLAY]
[HELP]
> [CREDITS]
[EXIT]
As you can see the function, keyboard.read ran twice for a single input. Do you know why? And if so how can I fix this? Thanks!