I'm trying to read a character instantly from command line without use of Enter. The ruby (ruby 1.9.3p374) code that I'm using is the following:
require 'io/console'
ch = STDIN.getch
puts ch
until now everithing is working fine but now i want to put this code inside an infinite loop doing some other stuff, something like
loop do
puts "..doing stuff.."
ch = STDIN.getch
if ch == 'q'
break
end
end
but this code always force that we press a key between each printing. I want a behaviour similar to STDIN.read_nonblock method but without having to press enter key after pressing one char.
Basically I want to print "..doing stuff.." until I press a certain key on keyboard but i don't want to use enter.
Any help will be appreciated. Thanks