Keyboard condition

Asked

Viewed 69 times

0

I am wanting to make a condition through the keys that the user press. For example, if it press 'ENTER' the script continues and press 'ESC' the script to. I searched the internet but found nothing specific. Any suggestions for a library?

ps: I am programmed in Python.

  • You can use the library keyboard and set events for each key.

1 answer

1

from pynput import *
from pynput.keyboard import Key, Listener

def on_release(key):
    if key == Key.enter:
        _thread.start_new_thread(iniciar,())
    if key == Key.esc:
        exit()

with Listener(on_release=on_release) as listener:   listener.join()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.