Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How do I scan for keypresses in console ruby?

Reply
Thread Tools

How do I scan for keypresses in console ruby?

 
 
Myrddin Emrys
Guest
Posts: n/a
 
      07-24-2006
I'm writing some text apps that need keyboard scanning... the only
module I've seen that does keypress scanning in Ruby is SDL, but that
sucks in X if I try to install it (Gentoo)... I don't even have X
installed. Is there a module that does keyboard scanning in Ruby that
isn't oriented toward X?

Thanks

Myrddin

 
Reply With Quote
 
 
 
 
Daniel Martin
Guest
Posts: n/a
 
      07-24-2006
"Myrddin Emrys" <(E-Mail Removed)> writes:

> I'm writing some text apps that need keyboard scanning... the only
> module I've seen that does keypress scanning in Ruby is SDL, but that
> sucks in X if I try to install it (Gentoo)... I don't even have X
> installed. Is there a module that does keyboard scanning in Ruby that
> isn't oriented toward X?


Check out cbreak.rb that is shipped with ruby as a sample program.

This doesn't do quite what you want, but if you take the three
functions from that file, then you can play around with this code:

cbreak
while true do
if select( [$stdin], nil, nil, 10 ) then
puts "saw character ", $stdin.read(1)[0]
else
puts "Ten seconds elapsed with no input"
end
end
cooked

Note: Likely not to work on windows. In fact, it may not even work
anywhere, although it probably will if you make sure that the values
for the TIOCGETP and TIOCSETP constants match your system's headers.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
keypresses and signal handling Rich C Programming 29 09-27-2010 10:31 AM
intercepting keypresses, mouse movements, joystick movements. bryan rasmussen Python 2 10-09-2006 07:11 PM
Re: JTable in Applet doesn't receive keypresses under Win2000 (XP is Ok) Dag Sunde Java 0 12-30-2004 04:16 PM
Detecting multiple keypresses kstahl C Programming 7 05-13-2004 05:43 PM



Advertisments