当我在中使用getch库并使用Linux时,如何在中使用kbhit函数?我在msvcrt库中找到了kbhit函数,但我不使用msvcrt,因为它只适用于Windows,而且我无法为getch库找到任何东西。
这是我现在的代码:
import getch
import threading
def onkey():
while getch.kbhit():
input = str(getch.getch())
print(input)
t = threading.Thread(target=onkey)
t.daemon = True
t.start()发布于 2022-05-29 21:06:15
KBHIT -“如果键盘字符被击中,返回True,否则为False。”
所以当你按下任何键,它就会返回True。如果您想知道您按了哪个键:
import getch
key = getch.getch().decode('utf-8')
print(key)https://stackoverflow.com/questions/70746303
复制相似问题