I know about "a = gets", but I need to read characters from keyboard without pressing enter. How can I do this in ruby?
Asked
Active
Viewed 1,827 times
2
-
Is that what you are looking for? http://stackoverflow.com/questions/946738/detect-key-press-non-blocking-w-o-getc-gets-in-ruby – moodywoody Apr 01 '12 at 11:12
-
http://stackoverflow.com/questions/174933/how-to-get-a-single-character-without-pressing-enter – joelparkerhenderson Apr 01 '12 at 11:43
2 Answers
1
You can try the STDIN, please check its document. It's a powerful tool to control your standard input .

staticor
- 620
- 9
- 19
1
use the green_shoes gem or simply use red shoes, here a green_shoes working sample
['green_shoes'].each(&method(:require))
Shoes.app do
e = edit_line
info = para "NO KEY is PRESSED."
keypress do |k|
info.replace "#{k.inspect} was PRESSED."
print k
end
end
Works on any OS unlike the sollution from Detect key press (non-blocking) w/o getc/gets in Ruby Put your shoes on !
-
Nifty! Thanks for sharing this - it's very different and a neat approach. – joelparkerhenderson Apr 01 '12 at 15:39
-
thanks, i advise to ta a good look at green shoes, it's amazing what you can do with it, could you accept my answer please ? – peter Apr 01 '12 at 18:43