[英]Trouble in detecting key presses in python using getch
我是python的新手,正在尝试制作主机游戏。 为了检测按键,我正在使用getch( https://github.com/joeyespo/py-getch )。 但是当我按a时,代码开始重复。
key = getch()
while (True):
if (key == 'a'):
principal.adicionaragua()
principal.gastaragua()
principal.aumentardias()
principal.estado()
time.sleep(2)
clear()
编辑 :我正在使用Windows和Python 2.7
您需要在循环中获取key
。 否则,由于您不检查循环内部,因此它将始终为'a'
。
while (True):
key = getch()
if (key == 'a'):
principal.adicionaragua()
principal.gastaragua()
principal.aumentardias()
principal.estado()
time.sleep(2)
clear()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.