| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Win32::AutoItX; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Win32::AutoItX - Automate the Windows GUI using AutoItX |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Win32::AutoItX; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $a = Win32::AutoItX->new; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
### AutoItX native methods ### |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $pid = $a->Run('calc.exe'); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $clipboard_text = $a->ClipGet; |
|
18
|
|
|
|
|
|
|
$a->ClipPut("Win32::AutoItX rulez!"); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $color = $a->PixelGetColor(42, 42); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
### Perlish methods ### |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $window = $a->get_window('Calculator'); |
|
25
|
|
|
|
|
|
|
$window->wait; |
|
26
|
|
|
|
|
|
|
for my $control ($window->find_controls) { |
|
27
|
|
|
|
|
|
|
local $\ = "\n"; |
|
28
|
|
|
|
|
|
|
print "Control $control"; |
|
29
|
|
|
|
|
|
|
print "\thandle: ", $control->handle; |
|
30
|
|
|
|
|
|
|
print "\ttext: ", $control->text; |
|
31
|
|
|
|
|
|
|
print "\tx: ", $control->x, "\ty: ", $control->y; |
|
32
|
|
|
|
|
|
|
print "\twidth: ", $control->width, "\theight: ", $control->height; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $button_2 = $window->find_controls('2', class => 'Button'); |
|
36
|
|
|
|
|
|
|
my $button_3 = $window->find_controls('3', class => 'Button'); |
|
37
|
|
|
|
|
|
|
my $button_plus = $window->find_controls('+', class => 'Button'); |
|
38
|
|
|
|
|
|
|
my $button_eq = $window->find_controls('=', class => 'Button'); |
|
39
|
|
|
|
|
|
|
my $result = $window->find_controls('0', class => 'Static'); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$button_2->click; |
|
42
|
|
|
|
|
|
|
$button_3->click; |
|
43
|
|
|
|
|
|
|
$button_plus->click; |
|
44
|
|
|
|
|
|
|
$button_3->click; |
|
45
|
|
|
|
|
|
|
$button_2->click; |
|
46
|
|
|
|
|
|
|
$button_eq->click; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
print "23 + 32 = ", $result->text, "\n"; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Win32::AutoItX helps to automate the Windows GUI using the AutoItX COM |
|
55
|
|
|
|
|
|
|
interface. To use this module you have to install AutoIt v3 |
|
56
|
|
|
|
|
|
|
(https://www.autoitscript.com/autoit3/) or register the AutoItX COM/ActiveX |
|
57
|
|
|
|
|
|
|
component. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
On the first constructor (L) invoke it tries to initialize the COM |
|
60
|
|
|
|
|
|
|
library. To avoid issues with the security context don't import L |
|
61
|
|
|
|
|
|
|
module in the same script using C |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
|
66
|
|
|
|
|
|
|
|
|
67
|
1
|
|
|
1
|
|
492
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
26
|
|
|
68
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
23
|
|
|
69
|
|
|
|
|
|
|
|
|
70
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
62
|
|
|
71
|
1
|
|
|
1
|
|
298
|
use Win32::AutoItX::Window; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
575
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $initialized; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 new |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$obj = Win32::AutoItX->new(%options) |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
creates a new instance of Win32::AutoItX object. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Available options: |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item debug |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
enables the debug mode (Win32::AutoItX will print additional information for |
|
90
|
|
|
|
|
|
|
debugging). |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item ole_warn |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
determines the behavior of the L module when an error happens. |
|
95
|
|
|
|
|
|
|
Please see L. Default is 3 (Carp::croak). |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item ole_cp |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
determines the codepage used by all translations between Perl strings and |
|
100
|
|
|
|
|
|
|
Unicode strings used by the OLE interface. Please see L. Default |
|
101
|
|
|
|
|
|
|
is CP_UTF8. |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub new { |
|
108
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Initialize COM and set Impersonation Level to RPC_C_IMP_LEVEL_DELEGATE |
|
111
|
0
|
0
|
0
|
|
|
|
if (not $initialized or $initialized != $$) { |
|
112
|
0
|
|
|
|
|
|
eval { |
|
113
|
0
|
|
|
|
|
|
require Win32::API; |
|
114
|
0
|
0
|
|
|
|
|
my $CoInit = Win32::API->new( |
|
115
|
|
|
|
|
|
|
"OLE32.DLL", "CoInitialize", "P", "N" |
|
116
|
|
|
|
|
|
|
) or croak "Can't find CoInitialize"; |
|
117
|
0
|
0
|
|
|
|
|
my $CoInitSec = Win32::API->new( |
|
118
|
|
|
|
|
|
|
"OLE32.DLL", "CoInitializeSecurity", "PNPPNNPNP", "N" |
|
119
|
|
|
|
|
|
|
) or croak "Can't find CoInitializeSecurity"; |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $result = $CoInit->Call(0); |
|
122
|
0
|
0
|
0
|
|
|
|
croak "CoInitialize failed: $result" |
|
123
|
|
|
|
|
|
|
if not defined $result or $result != 0; |
|
124
|
0
|
|
|
|
|
|
$result = $CoInitSec->Call(0, -1, 0, 0, 0, 4, 0, 0, 0); |
|
125
|
0
|
0
|
0
|
|
|
|
croak "CoInitializeSecurity failed: $result" |
|
126
|
|
|
|
|
|
|
if not defined $result or $result != 0; |
|
127
|
|
|
|
|
|
|
}; |
|
128
|
0
|
0
|
0
|
|
|
|
carp $@ if $@ and $ENV{AUTOITX_DEBUG}; |
|
129
|
0
|
|
|
|
|
|
$initialized = $$; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
require Win32::OLE; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my %args = ( |
|
135
|
|
|
|
|
|
|
debug => $ENV{AUTOITX_DEBUG}, |
|
136
|
0
|
|
|
|
|
|
ole_warn => 3, |
|
137
|
|
|
|
|
|
|
ole_cp => Win32::OLE->CP_UTF8, |
|
138
|
|
|
|
|
|
|
@_ |
|
139
|
|
|
|
|
|
|
); |
|
140
|
|
|
|
|
|
|
my $self = { |
|
141
|
0
|
0
|
|
|
|
|
debug => $args{debug} ? 1 : 0, |
|
142
|
|
|
|
|
|
|
}; |
|
143
|
0
|
|
|
|
|
|
Win32::OLE->Option(Warn => $args{ole_warn}); |
|
144
|
0
|
|
|
|
|
|
Win32::OLE->Option(CP => $args{ole_cp}); |
|
145
|
0
|
|
|
|
|
|
$self->{autoit} = Win32::OLE->new('AutoItX3.Control'); |
|
146
|
|
|
|
|
|
|
print "AutoItX version ", $self->{autoit}->version, "\n", |
|
147
|
|
|
|
|
|
|
"Win32::AutoItX version $VERSION\n" |
|
148
|
0
|
0
|
|
|
|
|
if $self->{debug}; |
|
149
|
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return bless $self, $class; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 debug |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
$debug_is_enabled = $obj->debug |
|
157
|
|
|
|
|
|
|
$obj = $obj->debug($enable_debug) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
if the argument is defined it enables or disables the debug mode and returns |
|
160
|
|
|
|
|
|
|
the object reference. Otherwise it returns the current state of debug mode. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub debug { |
|
165
|
0
|
|
|
0
|
1
|
|
my ($self, $value) = @_; |
|
166
|
0
|
0
|
|
|
|
|
if (defined $value) { |
|
167
|
0
|
0
|
|
|
|
|
$self->{debug} = $value ? 1 : 0; |
|
168
|
0
|
|
|
|
|
|
return $self; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
0
|
|
|
|
|
|
return $self->{debug}; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 list_windows |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
$hash_ref = $obj->list_windows($win_title) |
|
177
|
|
|
|
|
|
|
$hash_ref = $obj->list_windows($win_title, $win_text) |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
returns a hash reference with C<$handler =E $title> elements. Optionally |
|
180
|
|
|
|
|
|
|
windows can be filtered by title and/or text. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub list_windows { |
|
185
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
186
|
0
|
|
|
|
|
|
my $list = $self->{autoit}->WinList(@_); |
|
187
|
0
|
0
|
0
|
|
|
|
return {} unless ref $list and ref $list eq 'ARRAY'; |
|
188
|
0
|
|
|
|
|
|
my %result; |
|
189
|
0
|
|
|
|
|
|
for my $i (1 .. $#{$list->[0]}) { |
|
|
0
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
$result{$list->[1][$i]} = $list->[0][$i]; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
0
|
|
|
|
|
|
return \%result; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 get_window |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
$window = $a->get_window($title) |
|
199
|
|
|
|
|
|
|
$window = $a->get_window($title, $text) |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
returns a L object for the window with specified title |
|
202
|
|
|
|
|
|
|
and text (optionally). |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub get_window { |
|
207
|
0
|
|
|
0
|
1
|
|
return Win32::AutoItX::Window->new(@_); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head2 AutoItX methods |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This module also autoloads all AutoItX methods. For example: |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
$obj->WinActivate($win_title) unless $obj->WinActive($win_title); |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Please see AutoItX Help file for documenation of all available methods. |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
222
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
223
|
0
|
|
|
|
|
|
my $method = our $AUTOLOAD; |
|
224
|
0
|
|
|
|
|
|
$method =~ s/.*:://; |
|
225
|
0
|
0
|
|
|
|
|
print "Call AutoItX method $method with params: @_\n" |
|
226
|
|
|
|
|
|
|
if $self->debug; |
|
227
|
0
|
|
|
|
|
|
$self->{autoit}->$method(@_); |
|
228
|
|
|
|
|
|
|
} |
|
229
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head1 ENVIRONMENT VARIABLES |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 AUTOITX_DEBUG |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
enables additional output to the STDOUT. Can be overwrited with C option |
|
236
|
|
|
|
|
|
|
in the constructor (L) or with method L. |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=over |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=item L |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item L |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item AutoItX Help |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item https://www.autoitscript.com/autoit3/docs/ |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item L |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHOR |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Mikhail Telnov EMikhail.Telnov@gmail.comE |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Mikhail Telnov. |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
This library is free software; you may redistribute and/or modify it |
|
263
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; |