Leonard Schütz
Leonard Schütz

Reputation: 526

Read a single char from stdin without pressing enter

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

Upvotes: 10

Views: 949

Answers (1)

asterite
asterite

Reputation: 2926

Try this:

char = STDIN.raw &.read_char
p char

Upvotes: 19

Related Questions