Thanks much.  I'll give it a try.  Something I also noticed was the
following:  select([$stdin],nil,nil) always returns true when called
immediately before calling gets() on Windows. Hmmm....

Kind Regards,

Ken.

"daz" <dooby / d10.karoo.co.uk> wrote in message
news:pbCdnQhPWaQC2g3dSa8jmA / karoo.co.uk...
>
> >
> > If anyone knows the work-around to this, please add.
> >
>
> Hope this is of general use for STDIN#gets in a thread.
> It checks for input in the keyboard buffer and if there
> is any, does a normal (blocking) STDIN#gets.
>
>
> # STDIN#wt_gets for Windows
> # Doesn't block threads until there's input.
>
> # Won't run from GUIs (e.g. RDE, SciTE ...)
> #  (see kbhit API docs.)
>
> require 'Win32API'
> W_kbhit = Win32API.new('msvcrt', '_kbhit', '',  'I')
>
> def STDIN.key_wait
>   while W_kbhit.call == 0; sleep 0.1; end
> end
>
> def STDIN.wt_gets
>   key_wait
>   gets
> end
>
> #----- Usage ...
>
> STDOUT.sync = true
>
> Thread.new do
>   loop do
>     puts Time.now
>     sleep 1
>   end
> end
>
> Thread.new do
>   loop do
>     inp = STDIN.wt_gets.chomp!
>     inp.upcase == 'EXIT' and Thread.exit
>     puts inp
>   end
> end.join
>
> puts "\n\nPress a key to really exit ...\n\n"
> STDIN.key_wait  # defined above
>
> #----------
>
> I tried a VRuby GUI solution but it became a bit too
> feature-packed.  Couldn't hold myself back :-)
>
>
> daz
>
>
>