我需要从
stdin
读取按键而不阻塞,并且不仅仅在按下换行符时接收它们。我希望它的格式化方式是一个序列,其中每个项目都是自上次调用此过程以来按下的每个键的按键或 ascii 字符。
我尝试了以下代码:
while true:
let ch = readChar(stdin)
echo ch
但是只有在我按下换行符后才会收到密钥,然后它们会一一进入。
您尝试过https://github.com/johnnovak/illwill吗?
类似的东西:
import os, illwill
illwillInit()
while true:
var key = getKey()
case key
of Key.None: discard
of Key.Escape, Key.Q:
break
else:
echo "Key pressed: ", $key
sleep(20)