Sensing keyboard and mouse?

I want to interrupt something, when the user presses a key, or clicks
the mouse. The only solution for the keyboard I could come with, seems
overkill:

a=0
th=Thread.new {loop{a=STDIN.getc}}
loop do
a=0
sleep (1)
if a==0
puts “nothing pressed”
else
puts “key pressed”
end
end

Also, it requires that I press the Enter key… I would be very
grateful, if you could show me a better way.

Arun

On Aug 21, 2007, at 7:05 AM, arun wrote:

if a==0
puts “nothing pressed”
else
puts “key pressed”
end
end

Also, it requires that I press the Enter key… I would be very
grateful, if you could show me a better way.

Arun

Check out the termios library - and the HighLine gem.

Sorry if it’s brief, I have to run!
Ari
-------------------------------------------|
Nietzsche is my copilot

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs