This is a short section, but essential.
All the windows in Windows (heh) have invisible ID numbers. At any given time there may be dozens of these on your screen, since many utilities create invisible windows for various purposes. We need to find the ID of the There window, so that we can send it keystrokes, mouseclicks, and so forth.
Put a couple of lines like this in your script:
$therewin = &GetThereWindow();
if (! $therewin) {die "No There window found.";}
and then paste this subroutine into the bottom of your script file:
sub GetThereWindow {
# returns hook on the There window or null string if fails
my @w = Win32::GuiTest::FindWindowLike();
my $title;
for (@w) {
$title = Win32::GuiTest::GetWindowText($_);
if ($title =~ m/^There \(...\)") { return $_;}
}
return "";
}
Basically we're just looping through all the window titles
and using the fact that the There window is titled
"There (xxx)" for some xxx.Now that we've found the There window, we want to send it a SHIFT-CTRL-L. Why? Because this turns on the localhost:9999 server inside the There client and thus enables a whole new set of ways to interact with the There world!
The invocation in your script is
&SendShiftCtrlL($therewin);where $therewin is as returned by GetThereWindow. The subroutine that does the work is
sub SendShiftCtrlL {
# send SHIFT-CTRL-L to a specified window
my $wintarget = shift;
my $winsave = Win32::GuiTest::GetForegroundWindow();
Win32::GuiTest::SetForegroundWindow($wintarget);
sleep 1;
Win32::GuiTest::SendKeys("^+L");
Win32::GuiTest::SetForegroundWindow($winsave);
return 0;
}
Notice that we save the foreground window (presumably your Perl
command window), and then restore it when we are done. In between,
we have to change the focus to the There window, so that the
keystroke goes to the right place. We sleep for a second to
let the focus settle down. (You might be able to get away with
a shorter pause, but we haven't introduced a millisecond
timer yet in our lesson plan!)To understand the magical string ^+L you'll need to read the Win32-GuiTest documentation.
Next: Part 3