[英]How to Read Key pressed in python
你如何在不下載其他東西的情況下向上、向下和左右移動一個圓圈( pygame
)? 我嘗試使用getch
但它不起作用。 有人能幫我嗎?
這是我的代碼:
import msvcrt
key = msvcrt.getch()
while True:
print(key)
在 Windows 上,您應該使用
if msvcrt.kbhit():
c = msvcrt.getch()
在輪詢循環內。
除了安裝模塊之外,您不能做任何事情。 我強烈建議您使用keyboard
。 它易於使用,與其他模塊不同,它可以工作。
這是一個將檢測c
的示例代碼:
import keyboard
while True:
if keyboard.is_pressed("c"): #It will not include capital C
print("C pressed!")
break
它將接收來自整個 Windows 的密鑰
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.