Код: Выделить всё
import os
import CONTROLS # File with ASCII values
# UP DOWN RIGHT LEFT
if os.name == "posix":
CONTROL_CODES = range(65, 69)
else:
CONTROL_CODES = (72, 80, 77, 75)
pressed = None
def _input_control_codes(char):
global pressed
match char:
case CONTROL_CODES[0]: # UP
pressed = CONTROLS.UP
return
case CONTROL_CODES[1]: # DOWN
pressed = CONTROLS.DOWN
return
case CONTROL_CODES[2]: # RIGHT
pressed = CONTROLS.RIGHT
return
case CONTROL_CODES[3]: # LEFT
pressed = CONTROLS.LEFT
return
_input_control_codes(65) # example
print(pressed)
Код: Выделить всё
File "~/main.py", line 14
case CONTROL_CODES[0]: # UP
^
SyntaxError: invalid syntax
Подробнее здесь: https://stackoverflow.com/questions/790 ... s-the-case