In Ruby, I need a simple thread that will run some code every time I press a key. Is there any way to do this?
I need to be able to record Page UpandPage Down
Here is what I tried:
Thread.new do
while c = STDIN.getc
puts c.chr
end
end
loop do
puts Time.new
sleep 0.7
end
It almost works. There is only 1 problem, you need to strike back after each keystroke. I think this is due to I / O buffering.
source
share