sensing keyboard and mouse?

A

arun

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
 
A

Ari Brown

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

Check out the termios library - and the HighLine gem.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top