#!/usr/bin/perl # (C) 2008 Bolet Consulting. All rights reserved. # Based on the original example of Dennis K. Paulsen. use strict; use warnings; use X11::GUITest qw(:ALL); sub exit_me (); my $GEMainWin = 0; my $GEAboutWin = 0; my $greeting = "Hello, World\n"; my $title = "I am working by myself!\nI am beautiful and so is Perl!\n"; print "$0 : Script Start\n"; StartApp('gedit'); ( ($GEMainWin) = WaitWindowViewable('Un.*gedit', undef, 120) ) or die('Unable to find editor window!'); my @window_data = GetWindowPos($GEMainWin); my $x = shift @window_data; my $y = shift @window_data; # Send some text to the editor (TEXT x NUM TIMES) WINDOW: while (1) { SetKeySendDelay(150); SendKeys($greeting) or die('Unable to send text to editor!'); exit_me() if IsMouseButtonPressed(M_MIDDLE); SendKeys("{BAC}" x length($greeting)); exit_me() if IsMouseButtonPressed(M_MIDDLE); # Ensure the window changes its name to include the # 'modified' word since we sent it text above. (GetWindowName($GEMainWin) =~ /^\*/i) or die('Editor did not switch its title as expected!'); # Using shortcuts (Alt-h, a), open about box and wait for it SetKeySendDelay(50); exit_me() if IsMouseButtonPressed(M_MIDDLE); SendKeys('%(h)a'); ( ($GEAboutWin) = WaitWindowViewable('About gedit') ) or die('Unable to find about box!'); # Close about box (Alt-c) using shortcut for Close button. # and do some more fancy stuff SendKeys('%(c)'); exit_me() if IsMouseButtonPressed(M_MIDDLE); MoveMouseAbs($x + 5, $y + 150); SendKeys($title); PressMouseButton(M_LEFT); MoveMouseAbs($x + 5, $y + 250); ReleaseMouseButton(M_LEFT); SendKeys('{PAUSE 1500}'); exit_me() if IsMouseButtonPressed(M_MIDDLE); SendKeys("{BAC}"); PressMouseButton(M_MIDDLE); ReleaseMouseButton(M_MIDDLE); sleep 2; exit_me() if IsMouseButtonPressed(M_MIDDLE); } print "$0 : Script End (Success)\n"; sub exit_me () { # Now close the editor using menu short-cuts SendKeys('%(f)q'); sleep 1; # Select Close _w_ithout saving SendKeys('%(w)') or die('Unable to select Don\'t Save button!'); # Ensure main window gets closed WaitWindowClose($GEMainWin) or die('The editor window did not close!'); exit; }