Dale Martenson
1/24/2006 3:56:00 PM
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