如何读取自上次调用函数以来 nim 中按下的所有按键,而不需要按 Enter

问题描述 投票:0回答:1

我需要从

stdin
读取按键而不阻塞,并且不仅仅在按下换行符时接收它们。我希望它的格式化方式是一个序列,其中每个项目都是自上次调用此过程以来按下的每个键的按键或 ascii 字符。

我尝试了以下代码:

while true:
    let ch = readChar(stdin)
    echo ch

但是只有在我按下换行符后才会收到密钥,然后它们会一一进入。

keyboard stdin nim-lang
1个回答
0
投票

您尝试过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)
© www.soinside.com 2019 - 2024. All rights reserved.