Win32::AutoItX::Window - OO interface for Windows
use Win32::AutoItX; my $a = Win32::AutoItX->new; my $pid = $a->Run('calc.exe'); my $window = $a->get_window('Calculator'); $window->wait; local $\ = "\n"; print "Handle: $window"; print "Title: ", $window->title; print "PID: ", $window->process; print "x = ", $window->x, " y = ", $window->y; print "width = ", $window->width, " height = ", $window->height; $window->maximize; sleep 2; $window->restore; sleep 2; $window->move($window->x + 50, $window->y + 50); my $control = $window->get_focus; print "Focused control is $control with text = ", $control->text; # List all buttons my @buttons = $window->find_controls(undef, class => 'Button'); foreach my $c (@buttons) { print "Button '$c' has text ", $c->text; }
Win32::AutoItX::Window provides an object-oriented interface for AutoItX methods to operate with Windows.
$window = Win32::AutoItX::Window->new($autoitx, $window_title, $window_text)
creates the window object.
@class_list = $window->get_class_list()
retrieves list with classes from the window.
$control = $window->get_control($control_id)
returns a Win32::AutoItX::Control object for the control specified by id.
$control = $window->get_focus()
returns a Win32::AutoItX::Control object for the control that has keyboard focus within the window.
$control = $window->find_controls($text, %options) @controls = $window->find_controls($text, %options)
returns a Win32::AutoItX::Control object (or a list of objects in the list context) for matched contols. $text is a raw string or a Regexp.
$text
Regexp
Available options to filter controls:
a raw string or a Regexp to filter by Control's class.
get visible controls only (set by default).
get enabled controls only.
$control = $w->wait_control(%options)
waits until the control will be visible and enabled (optionally) and returns a Win32::AutoItX::Control object.
Optional arguments:
the control id
a raw string or a Regexp to filter controls by class
a raw string or a Regexp to filter controls by text
if true wait until the control will be enabled
timeout in seconds to wait the control (60 by default)
$handle = $window->handle()
retrieves the internal handle of the window.
$process = $window->process()
retrieves the Process ID (PID) associated with the window.
$state = $window->state()
returns a value indicating the state of the window. Multiple values are added together so use biwise Bitwise And (&) to examine the part you are interested in:
&
1 = Window exists 2 = Window is visible 4 = Windows is enabled 8 = Window is active 16 = Window is minimized 32 = Windows is maximized
For example:
print "Window is visible and enabled." if $window->state() & 6;
$boolean = $window->exists()
checks to see if the specified window exists.
$boolean = $window->is_active()
checks to see if the window exists and is currently active.
$text = $window->text()
retrieves the text from the window. Up to 64KB of window text can be retrieved. It works on minimized windows, but only works on hidden windows if you've set
$window->AutoItSetOption(WinDetectHiddenText => 1)
$title = $window->title()
retrieves the full title from the window.
$x = $window->x()
retrieves the X coordinate of the window.
$y = $window->y()
retrieves the Y coordinate of the window.
$width = $window->width()
retrieves the width of the window.
$height = $window->height()
retrieves the height of the window.
$client_width = $window->client_width()
retrieves the width of the window's client area.
$client_height = $window->client_height()
retrieves the height of the window's client area.
$window->activate()
activates (gives focus to) the window.
$window->close()
closes the window.
$window->kill()
forces the window to close.
$window->select_menu_item($item1, $item2, ..., $item7)
invokes a menu item of the window. You should note that underlined menu items actually contain a & character to indicate the underlining. You can access menu items up to six levels deep; and the window can be inactive, minimized, and/or even hidden. It will only work on standard menus. Unfortunately, many menus in use today are actually custom written or toolbars "pretending" to be menus. This is true for most Microsoft applications.
$window->move($x, $y) $window->move($x, $y, $width, $height)
moves and/or resizes the window. It has no effect on minimized windows, but it works on hidden windows. If very width and height are small (or negative), the window will go no smaller than 112 x 27 pixels. If width and height are large, the window will go no larger than approximately 12+DesktopWidth x 12+DesktopHeight pixels. Negative values are allowed for the x and y coordinates. In fact, you can move a window off screen; and if the window's program is one that remembers its last window position, the window will appear in the corner (but fully on-screen) the next time you launch the program.
12+DesktopWidth
12+DesktopHeight
$window->set_on_top($flag)
changes the window's "Always On Top" attribute. $flag determines whether the window should have the "TOPMOST" flag set: 1=set on top flag, 0 = remove on top flag.
$flag
$window->hide()
hides the window.
$window->show()
shows the previously hidden window.
$window->minimize()
minimizes the window.
$window->maximize()
maximizes the window.
$window->restore()
undoes the window minimization or maximization.
$window->set_title($title)
changes the title of the window.
$window->set_transparency($transparency)
sets the transparency of the window: a number in the range 0 - 255. The larger the number, the more transparent the window will become.
$window->wait() $window->wait($timeout)
pauses execution until the window exists. $timeout in seconds.
$timeout
$window->wait_active() $window->wait_active($timeout)
pauses execution until the window is active. $timeout in seconds.
$window->wait_not_active() $window->wait_not_active($timeout)
pauses execution until the window is not active. $timeout in seconds.
$window->wait_close() $window->wait_close($timeout)
pauses execution until the window does not exist. $timeout in seconds.
This module also autoloads all AutoItX methods. For example:
$window->WinActivate($win_title) unless $window->WinActive($win_title);
Please see AutoItX Help file for documenation of all available methods.
Mikhail Telnov <Mikhail.Telnov@gmail.com>
This software is copyright (c) 2017 by Mikhail Telnov.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
To install Win32::AutoItX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::AutoItX
CPAN shell
perl -MCPAN -e shell install Win32::AutoItX
For more information on module installation, please visit the detailed CPAN module installation guide.