Keypressed in Ruby

Hello. I have a small problem with Ruby. I am newbie in rubby and i need
to write something who works like this.

if keypressed = somekey
   do something

i tried to do it using Curses but getch function is waiting everytime
for
key and i don't want that. I want program to work independently from key
pressing unless the right key is pressed. Any tips for me?

def sitemonitor()
    Curses.noecho
    Curses.init_screen
    while true
      puts Curses.getch()
      for i in @listofSite
        if i.updatecheck()
          printf("some msg")
        end
      end
    end
end

···

--
Posted via http://www.ruby-forum.com/.

Quoting Kamil G. (lists@ruby-forum.com):

i tried to do it using Curses but getch function is waiting everytime
for
key and i don't want that. I want program to work independently from key
pressing unless the right key is pressed. Any tips for me?

With Curses, you have to set the terminal in Cbreak mode, otherwise
you will get data only when a carriage return is pressed. This is
obtained by calling

Curses::cbreak

Then, you may also want getch to be non-blocking. In Curses, this is a
per-window setting - see

ri Curses::Window#nodelay=

To set non-blocking getch for your main window, the instruction to use
is

Curses::stdscr.nodelay=true

Remember to close the screen before exiting the program, with

Curses::close_screen

Hope this helps

Carlo

···

Subject: Keypressed in Ruby
  Date: Fri 23 Nov 12 01:08:33PM +0900

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)