Read a single char from stdin without pressing ent

2019-06-24 01:05发布

问题:

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