【问题标题】:Scanning for up and down arrow in Go?在 Go 中扫描向上和向下箭头?
【发布时间】:2013-07-30 01:38:58
【问题描述】:

我正在尝试扫描 Go 中的向上和向下箭头键代码,但它似乎不起作用。到目前为止,我已经尝试过:

in = bufio.NewReader(os.Stdin)
b, err := in.ReadByte()
fmt.Println("Key code:", b, err)

但是当我按下向上或向下键时,它永远不会停止读取(它永远不会运行Println 语句)并且直接在终端中显示“^[[A”和“^[[B”。有什么想法吗?

【问题讨论】:

    标签: go stdin scanf keycode


    【解决方案1】:

    我相当肯定,如果没有 os 系统调用,您将无法轻松获得原始模式输入。看看Read a character from standard input in Go (without pressing Enter) 的答案。

    似乎普遍接受的解决方案是使用termbox-go,它显然具有相当好的跨平台能力。

    【讨论】:

    • 此外,您可能还想将 termbox-go 与 tcell 进行比较,后者在某些方面采用了不同的设计方法。 github.com/gdamore/tcell 可能更好或更糟,取决于您的需求。
    猜你喜欢
    • 2010-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    相关资源
    最近更新 更多