#!perl -w # # Written by Gabor Szabo # An example how to access the built in calculator (calc.exe) of Windows. # This code assumes your calulator defaults to the Standard view (and not the Scientific) use strict; use warnings; use Win32::GuiTest qw(:ALL); if (not @ARGV or ($ARGV[0] ne "keyboard" and $ARGV[0] ne "mouse")) { die "Usage: $0 [keyboard|mouse]\n" } system "start calc.exe"; sleep(1); my @windows = FindWindowLike(undef, "Calculator"); if (not @windows) { die "Could not find Calculator\n"; } if (@windows > 1) { die "There might be more than one Calculators running\n"; } if ($ARGV[0] eq "keyboard") { SendKeys('7'); sleep(1); SendKeys('\*'); sleep(1); SendKeys('5'); sleep(1); SendKeys('='); sleep(2); # Catch the content of the first child, # At this point we can only hope that this is the child that holds the result # as it does not have a title, maybe it has a type that we can check ? my @children = GetChildWindows($windows[0]); foreach my $child (@children) { printf "Result: %s\n",WMGetText($child) if (WMGetText($child) =~ m/^\d+$/s); } SendKeys("%{F4}"); # Alt-F4 to exit } if ($ARGV[0] eq "mouse") { my ($left, $top, $right, $bottom) = GetWindowRect($windows[0]); # find the appropriate child window and click on it my @children = GetChildWindows($windows[0]); foreach my $id (qw(137 92 135 121)) { my ($c) = grep {$id == GetWindowID($_)} @children; my ($left, $top, $right, $bottom) = GetWindowRect($c); MouseMoveAbsPix(($right+$left)/2,($top+$bottom)/2); SendMouse("{LeftClick}"); sleep(1); } foreach my $child (@children) { printf "Result: %s\n",WMGetText($child) if (WMGetText($child) =~ m/^\d+$/s); } MouseMoveAbsPix($right-10,$top+10); # this probably depends on the resolution sleep(2); SendMouse("{LeftClick}"); }