Read a single char from stdin without pressing enter

杀马特。学长 韩版系。学妹 提交于 2019-12-10 14:23:46

问题


How can I read a single char from the console without pressing enter / return?

In ruby I would just use:

require 'io/console'
input = STDIN.getch

回答1:


Try this:

char = STDIN.raw &.read_char
p char


来源:https://stackoverflow.com/questions/39964008/read-a-single-char-from-stdin-without-pressing-enter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!