The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Win32::AutoItX::Window - OO interface for Windows

SYNOPSIS

    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;
    }

DESCRIPTION

Win32::AutoItX::Window provides an object-oriented interface for AutoItX methods to operate with Windows.

METHODS

new

    $window = Win32::AutoItX::Window->new($autoitx, $window_title, $window_text)

creates the window object.

get_class_list

    @class_list = $window->get_class_list()

retrieves list with classes from the window.

get_control

    $control = $window->get_control($control_id)

returns a Win32::AutoItX::Control object for the control specified by id.

get_focus

    $control = $window->get_focus()

returns a Win32::AutoItX::Control object for the control that has keyboard focus within the window.

find_controls

    $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.

Available options to filter controls:

class

a raw string or a Regexp to filter by Control's class.

visible

get visible controls only (set by default).

enabled

get enabled controls only.

wait_control

    $control = $w->wait_control(%options)

waits until the control will be visible and enabled (optionally) and returns a Win32::AutoItX::Control object.

Optional arguments:

control

the control id

class

a raw string or a Regexp to filter controls by class

text

a raw string or a Regexp to filter controls by text

enabled

if true wait until the control will be enabled

timeout

timeout in seconds to wait the control (60 by default)

handle

    $handle = $window->handle()

retrieves the internal handle of the window.

process

    $process = $window->process()

retrieves the Process ID (PID) associated with the window.

state

    $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;

exists

    $boolean = $window->exists()

checks to see if the specified window exists.

is_active

    $boolean = $window->is_active()

checks to see if the window exists and is currently active.

text

    $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

    $title = $window->title()

retrieves the full title from the window.

x

    $x = $window->x()

retrieves the X coordinate of the window.

y

    $y = $window->y()

retrieves the Y coordinate of the window.

width

    $width = $window->width()

retrieves the width of the window.

height

    $height = $window->height()

retrieves the height of the window.

client_width

    $client_width = $window->client_width()

retrieves the width of the window's client area.

client_height

    $client_height = $window->client_height()

retrieves the height of the window's client area.

activate

    $window->activate()

activates (gives focus to) the window.

close

    $window->close()

closes the window.

kill

    $window->kill()

forces the window to close.

select_menu_item

    $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.

move

    $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.

set_on_top

    $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.

hide

    $window->hide()

hides the window.

show

    $window->show()

shows the previously hidden window.

minimize

    $window->minimize()

minimizes the window.

maximize

    $window->maximize()

maximizes the window.

restore

    $window->restore()

undoes the window minimization or maximization.

set_title

    $window->set_title($title)

changes the title of the window.

set_transparency

    $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.

wait

    $window->wait()
    $window->wait($timeout)

pauses execution until the window exists. $timeout in seconds.

wait_active

    $window->wait_active()
    $window->wait_active($timeout)

pauses execution until the window is active. $timeout in seconds.

wait_not_active

    $window->wait_not_active()
    $window->wait_not_active($timeout)

pauses execution until the window is not active. $timeout in seconds.

wait_close

    $window->wait_close()
    $window->wait_close($timeout)

pauses execution until the window does not exist. $timeout in seconds.

AutoItX native methods

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.

SEE ALSO

Win32::AutoItX::Control
Win32::AutoItX
AutoItX Help

AUTHOR

Mikhail Telnov <Mikhail.Telnov@gmail.com>

COPYRIGHT

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.