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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.