Interesting... I don't think I'll be able to take it much further, but this is what I found out:
use Win32::Console;
$StdIn = new Win32::Console(STD_INPUT_HANDLE);
my $key;
while (!(defined @event)) {
@event = $StdIn->PeekInput();
#@event = $StdIn->Input();
$key = chr($event[5]);
}
print join(" ", @event),"\n";
print "Got key $key!\n";
Using the commented line of Input, the program works as expected and only accepts input when in focus. Using PeekInput will work if you type something while in focus, but only if you haven't typed something in another window after starting the program.
Try running that code above, then after starting the program, type "a" into another window, then go back to the prompt. It won't get out of the loop... (Input doesn't have this issue).
I'm guessing this is a dead-end though. PeekInput seems to be useful for reading the input without removing it from the buffer, not necessarily reading from a buffer when the program isn't in focus.
Nonetheless, thanks for the suggestion. | [reply] [d/l] |