llee has asked for the wisdom of the Perl Monks concerning the following question:

I tried using the functions defined in Term::ReadKey. The readkey function returns keyboard events that occur while the application is still in focus. When the user brings another program into focus Readkey is unable to return key evens. I'm looking for something like windows GetKeyboardState ().

Replies are listed 'Best First'.
Re: windows events
by GrandFather (Saint) on Jul 12, 2006 at 03:19 UTC

    Those may be two different issues depending on what you are really trying to achieve. Term::ReadKey can be used for handling keyboard input in various ways and is not Windows specific.

    Perhaps you could tell us a little more about the problem you are trying to solve rather than asking about how to solve something we don't know about using tools that you think may provide the right solution (see XY Problem).


    DWIM is Perl's answer to Gödel
Re: windows events
by bsdz (Friar) on Jul 12, 2006 at 14:21 UTC
    If you're trying to determine if the keyboard is idle. You could interface to the GetLastInputInfo function using Win32:API. This returns a LASTINPUTINFO structure that contains the tick count since the last input event. The difference between this value and the actual tick count since system boot will give the milliseconds since last input. For example: -
    use strict; use Win32::API; my $tc = Win32::GetTickCount(); Win32::API::Struct->typedef( LASTINPUTINFO => qw{ UINT cbSize; DWORD dwTime; } ); Win32::API->Import("user32", 'BOOL GetLastInputInfo(LPLASTINPUTINFO pl +ii)'); my $li = Win32::API::Struct->new('LASTINPUTINFO'); $li->{cbSize} = $li->sizeof; # MSDN: Must be set to sizeof(LASTINPUTIN +FO) GetLastInputInfo($li); print $li->{dwTime} - $tc, "\n";