“Python Écoutez l'entrée du clavier” Réponses codées

Python comment écouter le clavier

import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('q'):  # if key 'q' is pressed 
            print('You Pressed A Key!')
            break  # finishing the loop
    except:
        break  # if user pressed a key other than the given key the loop will break
Dezach

Python Écoutez l'entrée du clavier

# For windows
from pynput import keyboard

def on_press(key):
    try:
        k = key.char  # single-char keys
    except:
        k = key.name  # other keys
    print('Key pressed: ' + k)
    return False  # stop listener; remove this if want more keys

listener = keyboard.Listener(on_press=on_press)
listener.start()  # start to listen on a separate thread
listener.join()  # remove if main thread is polling self.keys

Réponses similaires à “Python Écoutez l'entrée du clavier”

Questions similaires à “Python Écoutez l'entrée du clavier”

Plus de réponses similaires à “Python Écoutez l'entrée du clavier” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code