When I saw Get Numlock Status, I started thinking about how to acheive this. I couldn't come up with anything that worked until I started digging into the Windows API.

#!/usr/bin/perl use strict; use warnings; use Tk; use Win32::API; my $GetKeyState = new Win32::API("user32","GetKeyState", ['I'], 'I'); my ($num, $caps, $scroll); my $main = MainWindow->new(); my $form = $main->Frame()->pack(-side => 'top'); my $cl = $form->Frame()->pack(-side => 'left'); my $capslock = $cl->Entry(-width => 8)->pack(-side => 'left'); my $nl = $form->Frame()->pack(-side => 'left'); my $numlock = $nl->Entry(-width => 8)->pack(-side => 'left'); my $sl = $form->Frame()->pack(-side => 'left'); my $scrolllock = $nl->Entry(-width => 8)->pack(-side => 'left'); $main->repeat(100, \&UpdateKeyStates); MainLoop(); sub GetCapsLock { return 0+($GetKeyState->Call(0x14) != 0); } sub GetNumLock { return 0+($GetKeyState->Call(0x90) != 0); } sub GetScrollLock { return 0+($GetKeyState->Call(0x91) != 0); } sub UpdateEntry { my $entry = shift; my $text = shift; $entry->delete(0, 'end'); $entry->insert(0, $text); } sub UpdateKeyStates { $caps = GetCapsLock() ? 'Cap' : ''; $num = GetNumLock() ? 'Num' : ''; $scroll = GetScrollLock() ? 'Scroll' : ''; UpdateEntry($capslock, $caps); UpdateEntry($numlock, $num); UpdateEntry($scrolllock, $scroll); $main->title($caps.$num.$scroll); }


In reply to Show Status of Caps, Num, and ScrollLock on Win32 by Mr. Muskrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.