When using python with the keyboard module is there a way I can use enter to execute something within a program?
Asked
Active
Viewed 324 times
0
-
please be more precise, show what you've tried, or be more precise about your environment – midugh Feb 03 '21 at 21:15
-
https://github.com/boppreh/keyboard#keyboard.add_hotkey "enter" is the name of the enter key in there – h4z3 Feb 03 '21 at 21:19
-
I use "enter" within `keyboard.is_pressed("enter")` and it never works. – Dylan Guthrie Feb 03 '21 at 21:26
1 Answers
0
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.

vvvvv
- 25,404
- 19
- 49
- 81