简体   繁体   中英

Detect enter key pressed python

is there a way to detect if ENTER is pressed with python? I was able to detect letters with win32api using win32api.GetAsyncKeyState(ord('H')) , but couldn't do the same with enter. I need to run the code on windows. Thanks.

You can use keyboard lib.

pip3 install keyboard

import keyboard

if keyboard.read_key() == "enter":
    ...

https://github.com/boppreh/keyboard

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM