use strict; use warnings; use Tk; use Win32::API; # Windows constants my ($ONTOP, $NOTOP, $TOP) = (-1, -2, 0); my ($SWP_NOMOVE, $SWP_NOSIZE) = (2, 1); my $SetWindowPos = new Win32::API("user32", "SetWindowPos", 'NNNNNNN', 'N'); my $FindWindow = new Win32::API("user32", "FindWindow", 'PP', 'N'); my $GetForegroundWindow = new Win32::API("user32", "GetForegroundWindow",'','N'); my $GetWindowText = new Win32::API("user32", "GetWindowText",'NPI','I'); my $fg = 0; # foreground hWnd my $flashme = 'Waiting to show shortcut keys'; my $w = new MainWindow; my $fc = $w->Label(-textvariable => \$flashme, -justify => 'left')->pack; my $id = Tk::After->new($w,2000,'repeat',\&showFlashCard); my $flashcards = { 'Microsoft Outlook' => qq{Outlook CTRL-1 - Mail CTRL-2 - Calendar CTRL-4 - Task List CTRL-Y - Go to Folder... CTRL-E - Find... ALT-F1 - Toggle Nav Pane CTRL-SHIFT-V - Move Items to Folder... }, 'SQL Query Analyzer' => qq{Query Analyzer CTRL-D - Results as datagrid CTRL-T - Results as text CTRL-R - Toggle Results Pane CTRL-L - Execution Plan F8 - Toggle Object Browser CTRL-SHIFT-P - Open File }, 'Mozilla Firefox' => qq{Mozilla FireFox CTRL-L - Location CTRL-D - Add Bookmark CTRL-B - Bookmarks } }; # start the UI MainLoop; sub showFlashCard { my $thisfg = $GetForegroundWindow->Call(); if ($fg != $thisfg) { # Foreground Window has changed $fg = $thisfg; my $wt=' 'x150; my $i = $GetWindowText->Call($fg,$wt,150); $wt = substr($wt, 0, $i); #warn "$fg\t$wt\n"; # use this to ascertain window text for my $re (keys %$flashcards) { if ($wt =~ /$re/) { $flashme = $flashcards->{$re}; } } } # Reestablish Z order my $class = "TkTopLevel"; my $topHwnd = $FindWindow->Call($class, $w->title); $topHwnd and $SetWindowPos->Call($topHwnd, $ONTOP, 0, 0, 0, 0, $SWP_NOMOVE | $SWP_NOSIZE); }