In Ruby, I need a simple thread that would run some code every time a key in pressed. Is there a way to do that?
I need to be able to capture the Page Up and Page Down
Here is what I tried:
#!/usr/bin/env ruby
Thread.new do
while c = STDIN.getc
puts c.chr
end
end
loop do
puts Time.new
sleep 0.7
end
This almost works. There is only 1 issue, one needs to hit return after every key stroke. I guess this is because of buffered IO.