forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouredev.py
45 lines (36 loc) · 1.2 KB
/
mouredev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from pynput.keyboard import Key, KeyCode, Listener
KONAMI_CODE = [
Key.up, Key.up, Key.down, Key.down,
Key.left, Key.right, Key.left, Key.right,
KeyCode.from_char("b"), KeyCode.from_char("a")
]
key_position = 0
last_key = Key.esc
def on_press(key):
global key_position, last_key
if key == Key.esc:
print("Exit")
return False
if key == KONAMI_CODE[key_position]:
key_position += 1
elif key == KONAMI_CODE[0]:
# Se controla que se falle con la primera tecla válida
if last_key == KONAMI_CODE[0]:
# Se controla que se escriba varias veces la primera tecla válida
key_position = 2
else:
key_position = 1
else:
key_position = 0
if key_position == len(KONAMI_CODE):
print("""
\n
╦╔═╔═╗╔╗╔╔═╗╔╦╗╦ ╔═╗╔═╗╔╦╗╔═╗
╠╩╗║ ║║║║╠═╣║║║║ ║ ║ ║ ║║║╣
╩ ╩╚═╝╝╚╝╩ ╩╩ ╩╩ ╚═╝╚═╝═╩╝╚═╝
\n
""")
return False
last_key = key
with Listener(on_press=on_press) as listener:
listener.join()