#!/usr/bin/perl use warnings; use strict; use Win32::GuiTest qw(FindWindowLike GetWindowText SetForegroundWindow SendKeys MouseMoveAbsPix SendLButtonDown SendLButtonUp SendRButtonDown SendRButtonUp); $|=1; $Win32::GuiTest::debug = 0; # Set to "1" to enable verbose mode #set screen size my @x = (1 .. 1024); my @y = (1 .. 768); my $xcoord; my $ycoord; my @commands = ("MouseMoveAbsPix", "SendLButtonDown()", "SendLButtonUp()", "SendRButtonDown()", "SendRButtonUp()"); print "Enter the name of the window for monkey testing, i.e untitled - Paint :\n"; my $winName = ; chomp $winName; print "You have 10 seconds to bring that window to the forefront before PerlMonkeyTest takes over your machine!\n"; print "Use Task Manager to kill processes if your mouse is out of control.\n"; my @windows = FindWindowLike(0, "^$winName" ); #my @windows = FindWindowLike(0, "^untitled - Paint" ); # my @windows = FindWindowLike(0, "^Microsoft Excel", "^XLMAIN\$"); for (@windows) { print "$_>\t'", GetWindowText($_), "'\n"; SetForegroundWindow($_) or die "what window?"; sleep 10; while (1) { #set random $x, $y, 1024, 768 my $xcoord = $x[rand @x]; my $ycoord = $y[rand @y]; #choose random from @commands my $command = $commands[rand @commands]; if ($command =~ "Send") { eval $command; } else { eval "$command($xcoord,$ycoord)"; } sleep 1; } }