From: Dale Martenson Date: 2006-01-25T01:28:00+09:00 Subject: Re: How to capture a pressed key? Are you running on Windows or Linux? In Windows, you can do something like this: require 'Win32API' $win32_console_kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I') $win32_console_cputs = Win32API.new("msvcrt", "_cputs", ['P'], 'I') $win32_console_getch = Win32API.new("msvcrt", "_getch", [], 'I') def console_input_ready? $win32_console_kbhit.call != 0 end def console_input $win32_console_getch.call end def console_output( str ) $win32_console_cputs.call( str ) end while true if console_input_ready? then ch = console_input print "ch: <#{ch.chr}>\n" break else console_output( "." ) sleep 0.5 end end