【发布时间】:2013-11-21 16:41:12
【问题描述】:
PYTHON 3.3,msvcrt
import sys, msvcrt
print("Please press a key to see its value")
while 1:
key = msvcrt.getch()
print("the key is")
print(key)
if ord(key) == 27: # key nr 27 is escape
sys.exit()
这是我的代码,仅作为示例。
当代码到达key = msvcrt.getch()*, or *key = ord(getch()) 时,代码会暂停,在这里我使用了第一个。
我想让这段代码不断打印关键是
当我给出一个新的输入时(当我按下一个键时),而不是仅仅打印 key is。
所以打印的输出看起来像这样:
the key is
the key is
the key is
the key is
the key is
the key is
77
the key is
the key is
the key is
如果你想制作类似 snake 的东西,你不希望每次想要 getch 时都暂停你的游戏,这是需要的,你不希望它暂停,等待输入。
【问题讨论】: