forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mouredev#3972 from espinoleandroo/main
Reto mouredev#25 - python
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Retos/Reto #25 - EL CÓDIGO KONAMI [Media]/python/EspinoLeandroo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import keyboard | ||
|
||
# Código Konami a detectar | ||
konami_code = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a'] | ||
|
||
# Lista para almacenar las teclas ingresadas por el usuario | ||
user_input = [] | ||
|
||
# Función para verificar si se ingresó el Código Konami | ||
def check_konami_code(): | ||
if user_input == konami_code: | ||
print("¡Código Konami detectado!") | ||
|
||
# Función para manejar las teclas presionadas | ||
def on_key_press(event): | ||
key = event.name.lower() | ||
|
||
# Agregar la tecla a la lista de entrada del usuario | ||
user_input.append(key) | ||
|
||
# Verificar si se ingresó el Código Konami | ||
check_konami_code() | ||
|
||
# Limitar la lista de entrada del usuario al tamaño del Código Konami | ||
user_input[:] = user_input[-len(konami_code):] | ||
|
||
# Registrar el manejador de eventos para las teclas presionadas | ||
keyboard.on_press(on_key_press) | ||
|
||
# Mantener el programa en ejecución | ||
keyboard.wait() |