Hi,
I also thought of Term::ReadKey and gave it a shot, but it reports that
non-blocking mode does not work under windows.
Also looked at the 'select' statement, but that appears to only work for
sockets under windows.
Ken

> From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-
> win32-users-boun...@listserv.activestate.com] On Behalf Of JONES,
> ROBERT E CTR USAF AETC TTMS/TTMS
> Sent: Friday, October 07, 2011 1:06 PM
> To: Barry Brevik; perl-win32-users@listserv.activestate.com
> Subject: RE: Non-blocking keyboard?
> 
> 
>   You might want to look into the Term::Readkey module.
> 
> 
> Robert Jones, BSP, BSCS
> Keesler AFB
> 
> -----Original Message-----
> From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-
> win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik
> Sent: Friday, October 07, 2011 11:46 AM
> To: perl-win32-users@listserv.activestate.com
> Subject: Non-blocking keyboard?
> 
> I'm writing a program where a process runs in a loop. I want to process
> keyboard input without disturbing the main process in the loop. I'm
> trying to use the Win32::Console module for this task (see code below),
> but the module blocks on the Input statement.
> 
> Is there some way to make this non-blocking, or maybe even use a
> different technique entirely that does not block? I tried whipping an
> IOCTL statement on it, but I either did it wrong, or it does not work.
> 
> use strict;
> use warnings;
> use Win32::Console;
> 
> my $STDIN = new Win32::Console(STD_INPUT_HANDLE);
> $STDIN->Mode(ENABLE_PROCESSED_INPUT);
> 
> # Un-buffer STDOUT.
> select((select(STDOUT), $| = 1)[0]);
> 
> while (1)
> {
>   my @input = $STDIN->Input();
>   if (defined $input[0] and $input[0] == 1)
>   {
>     if ($input[1])
>     {
>       last if $input[5] == 27;  # ESC key.
>       if ($input[5] == 8) {print "\x08", ' ', "\x08"; next;}  #
> Backspace key.
>       print chr($input[5]);
>     }
>   }
> }
> 
> As an aside, I think we need to get more traffic on this list somehow.
> 
> Barry Brevik



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to