How do I scan for keypresses in console ruby?

Discussion in 'Ruby' started by Myrddin Emrys, Jul 24, 2006.

  1. 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
     
    Myrddin Emrys, Jul 24, 2006
    #1
    1. Advertising

  2. "Myrddin Emrys" <> 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.
     
    Daniel Martin, Jul 24, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dag Sunde
    Replies:
    0
    Views:
    422
    Dag Sunde
    Dec 30, 2004
  2. kstahl

    Detecting multiple keypresses

    kstahl, May 12, 2004, in forum: C Programming
    Replies:
    7
    Views:
    446
    Alan Balmer
    May 13, 2004
  3. bryan rasmussen
    Replies:
    2
    Views:
    361
    Jordan
    Oct 9, 2006
  4. Rich

    keypresses and signal handling

    Rich, Sep 25, 2010, in forum: C Programming
    Replies:
    29
    Views:
    1,318
    Ben Bacarisse
    Sep 27, 2010
  5. Replies:
    1
    Views:
    72
    Evertjan.
    Apr 14, 2007
Loading...

Share This Page