Scanning for up and down arrow in Go?

2019-02-19 15:31发布

I'm trying to scan for the up and down arrow key codes in Go, but it doesn't seem to be working. So far I've tried this:

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

But when I press the up or down key, it never stops reading (it never run the Println statement) and just displays "^[[A" and "^[[B" directly in the terminal. Any idea?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-02-19 16:12

I'm fairly certain you can't get raw mode input easily without os syscalls. Have a look at the answers to Read a character from standard input in Go (without pressing Enter) .

It seems that the generally accepted solution is to use termbox-go which apparently has fairly good cross platform capability.

查看更多
登录 后发表回答