Here is my full code, Please go through it... Let me know what are the errors, and the changes to be made.
#perl
use constant WM_KEYDOWN => 0x0100;
use constant WM_KEYUP => 0x0101;
use Win32::GuiTest qw(FindWindowLike MenuSelect WaitWindow WMSetText
+ PushChildButton GetSystemMenu SetForegroundWindow);
system('"start %windir%\system32\mstsc.exe"'); #--System prog
+ram to open the the Remote Desktop Connection application
sleep(2); #let me see the window
$max_Sleep_time=5; #--Maximum wait in sec to open the Remote Desk
+top Connection application
WaitWindow("Remote Desktop Connection",$max_Sleep_time);
@windows = FindWindowLike(0, "Remote Desktop Connection");
for (@windows) #--for each of the open windows do the follow
+ing
{
#--MenuSelect("&Close", 0, GetSystemMenu($_,FALSE));
hwndSendKeys($_,"%{F4}")
}
sub hwndSendKeys {
my ( $hwnd, $keys, $delay) = @_;
$delay = 25 unless defined $delay;
$delay /= 1000;
my @k = Win32::GuiTest::parse_keys($keys);
for ( my $i = 0; $i < @k; $i+=2) {
if ( defined $k[$i]) {
Win32::GuiTest::DbgShow("SendRawKey(@k[$i,$i+1])\n");
#~ Win32::GuiTest::SendRawKey( @k[$i,$i+1]);
my( $key, $updown ) = @k[ $i, $i+1 ] ;
my $wmupdown = WM_KEYDOWN();
$wmupdown = WM_KEYUP() if $updown == 2;
Win32::GuiTest::PostMessage( $hwnd, $wmupdown, $key , 0
+ );
select(undef,undef,undef,$delay); ## deprecated
$i+=2; ### SUPER BROKEN otherwise DOUBLING bug
} else {
$k[$i+1]-> ();
}
}
}
|