在Go中从标准输入中读取一个字符(无需按Enter键) [英] Read a character from standard input in Go (without pressing Enter)

查看:728
本文介绍了在Go中从标准输入中读取一个字符(无需按Enter键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



按任意键退出...



当我按下任何键时,它就会退出。

我该如何做到这一点?



注意:我已经使用了Google搜索功能,但是我发现所有内容都需要在最后按输入。我想在C#中使用像 Console.ReadKey()这样的东西。



我正在运行MS Windows。

解决方案

termbox-go 是一款轻量级的Go-native包,它提供了一些基本的终端控制。包括在原始模式下获取输入的能力(一次只读取一个字符,而没有默认的行缓冲行为)。

它在不同系统之间也具有相当好的兼容性。

并且键盘扩展了termbox-go以提供一些额外的键盘功能,例如多键快捷键和序列。

I want to my app shows:

press any key to exit ...

And when I pressed any key, it exits.

How can I achieve this?

Note: I have googled but all of what I've found needed to press enter at the end. I want something like Console.ReadKey() in C#.

I am running MS Windows.

解决方案

termbox-go is a light-weight Go-native package which offers some rudimentary terminal control. Including the ability to get input in raw mode (read one character at a time without the default line-buffered behaviour).

It also has fairly ok compatibility across different systems.

And keyboard extends termbox-go to give some additional keyboard functionality like multi-key shortcuts and sequences.

这篇关于在Go中从标准输入中读取一个字符(无需按Enter键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆