Python enter key press, keyboard module

446 Views Asked by At

When using python with the keyboard module is there a way I can use enter to execute something within a program?

1

There are 1 best solutions below

0
On

Use keyboard.add_hotkey to call the foobar function when pressing Enter.

import keyboard

def foobar():
    print("foo bar") 

keyboard.add_hotkey("enter", foobar)
keyboard.wait()

Source from the documentation.