From: Park Heesob Date: 2002-09-09T13:49:58+09:00 Subject: Re: Equivalent of pascal's keypressed ? Hi, ----- Original Message ----- From: "Philip Mateescu" Newsgroups: comp.lang.ruby Sent: Monday, September 09, 2002 9:41 AM Subject: Equivalent of pascal's keypressed ? > Hi, > > I'm looking for an equivalent to pascal's old keypressed. > I'm trying to execute a block till the user presses a key, something like : > > while (!keypressed) > print "." > end > > Is there any such functionality ? > > I'd also like to know if there is a way to trap the user pressing Ctrl-C > and do some stuff before closing ? > > Thank you very much, > philip > Is the following what you are looking for? require 'Win32API' kbhit = Win32API.new("crtdll", "_kbhit", [], 'L') getch = Win32API.new("crtdll", "_getch", [], 'L') trap("INT") do puts "ouch" exit end while kbhit.Call==0 print "." end puts "#{getch.Call.chr} pressed" Park Heesob