au3 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/AutoItX3/au3.rb +3 -5
- data/lib/AutoItX3/control.rb +511 -44
- data/lib/AutoItX3/filedir.rb +68 -21
- data/lib/AutoItX3/graphic.rb +29 -5
- data/lib/AutoItX3/keyboard.rb +18 -4
- data/lib/AutoItX3/misc.rb +85 -28
- data/lib/AutoItX3/mouse.rb +82 -16
- data/lib/AutoItX3/process.rb +116 -51
- data/lib/AutoItX3/window.rb +346 -61
- data/lib/AutoItX3/window/send_message.rb +271 -0
- data/lib/HISTORY.rdoc +10 -0
- data/lib/README.rdoc +26 -1
- data/lib/au3.rb +6 -0
- data/test/test_misc.rb +2 -1
- data/test/test_window_messages.rb +42 -0
- metadata +42 -16
data/lib/AutoItX3/au3.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
#Encoding: UTF-8
|
2
2
|
#This file is part of au3.
|
3
|
-
#Copyright © 2009 Marvin Gülker
|
3
|
+
#Copyright © 2009, 2010 Marvin Gülker, Steven Heidel
|
4
4
|
#
|
5
5
|
#au3 is published under the same terms as Ruby.
|
6
6
|
#See http://www.ruby-lang.org/en/LICENSE.txt
|
7
|
-
|
8
|
-
#===au3.rb
|
9
|
-
#This is au3's main file.
|
7
|
+
|
10
8
|
require "win32/api"
|
11
9
|
#(See the end of this file for more require statements)
|
12
10
|
|
@@ -83,7 +81,7 @@ module AutoItX3
|
|
83
81
|
INTDEFAULT = -2147483647
|
84
82
|
|
85
83
|
#The version of this au3 library.
|
86
|
-
VERSION = "0.1.
|
84
|
+
VERSION = "0.1.2"
|
87
85
|
|
88
86
|
#This is the buffer size used for AutoItX3's text "returning" functions.
|
89
87
|
#It will be subtracted by 1 due to the trailing 0 of wchar_t * type strings.
|
data/lib/AutoItX3/control.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
#Encoding: UTF-8
|
2
|
+
#This file is part of au3.
|
3
|
+
#Copyright © 2009, 2010 Marvin Gülker, Steven Heidel
|
4
|
+
#
|
5
|
+
#au3 is published under the same terms as Ruby.
|
6
|
+
#See http://www.ruby-lang.org/en/LICENSE.txt
|
2
7
|
|
3
8
|
module AutoItX3
|
4
9
|
|
@@ -13,15 +18,20 @@ module AutoItX3
|
|
13
18
|
|
14
19
|
class << self
|
15
20
|
|
16
|
-
def functions
|
21
|
+
def functions # :nodoc:
|
17
22
|
@functions
|
18
23
|
end
|
19
24
|
|
20
|
-
def functions=(hsh)
|
25
|
+
def functions=(hsh) # :nodoc:
|
21
26
|
@functions = hsh
|
22
27
|
end
|
23
28
|
|
24
29
|
#Generates a control by using another control.
|
30
|
+
#===Parameters
|
31
|
+
#[+ctrl+] The control to transform.
|
32
|
+
#===Return value
|
33
|
+
#A new instance of a subclass of Control.
|
34
|
+
#===Remarks & Example
|
25
35
|
#This function is meant to be used with subclasses of Control, so you can do
|
26
36
|
#things like this:
|
27
37
|
# #...
|
@@ -36,11 +46,18 @@ module AutoItX3
|
|
36
46
|
|
37
47
|
end
|
38
48
|
|
39
|
-
#Creates a new Control object.
|
40
|
-
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
49
|
+
#Creates a new Control object.
|
50
|
+
#===Parameters
|
51
|
+
#[+title+] The title of the window containing the control.
|
52
|
+
#[+text+] The text of the window containing the control Set to "" (empty string) if you don't care about it.
|
53
|
+
#[+control_id+] The ID of the control. You can also use the name of the control in combination with the occurence number of it, like "Edit1" and "Edit2".
|
54
|
+
#===Return value
|
55
|
+
#A brand new Control instance.
|
56
|
+
#===Raises
|
57
|
+
#[Au3Error] The control or the window doesn't exist.
|
58
|
+
#===Example
|
59
|
+
# #Get the edit control of the "Run" dialog:
|
60
|
+
# ctrl = AutoItX3::Control.new("Run", "", "Edit1")
|
44
61
|
def initialize(title, text, control_id)
|
45
62
|
@title = title
|
46
63
|
@text = text
|
@@ -48,8 +65,23 @@ module AutoItX3
|
|
48
65
|
visible? #Raises an error if the control doesn't exist
|
49
66
|
end
|
50
67
|
|
51
|
-
#Clicks +self+ with the given mouse +button
|
52
|
-
|
68
|
+
#Clicks +self+ with the given mouse +button+.
|
69
|
+
#===Parameters
|
70
|
+
#[+button+] (<tt>"Primary"</tt>)The button to click with.
|
71
|
+
#[+clicks+] (1) The number of clicks.
|
72
|
+
#[+x+] (+INTDEFAULT+) The X-coordinate to click at. Middle if left out.
|
73
|
+
#[+y+] (+INTDEFAULT+) The Y-coordinate to click at. Middle if left out.
|
74
|
+
#===Return value
|
75
|
+
#nil.
|
76
|
+
#===Raises
|
77
|
+
#[Au3Error] Couldn't click the control.
|
78
|
+
#===Example
|
79
|
+
# #Click with the left (or if left-handed mouse, right) button
|
80
|
+
# ctrl.click
|
81
|
+
# #Click with the secondary button
|
82
|
+
# ctrl.click("Secondary")
|
83
|
+
# #Double click
|
84
|
+
# ctrl.click("Primary", 2)
|
53
85
|
def click(button = "Primary", clicks = 1, x = INTDEFAULT, y = INTDEFAULT)
|
54
86
|
Control.functions[__method__] ||= AU3_Function.new("ControlClick", 'SSSSLLL', 'L')
|
55
87
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide, button.wide, clicks, x, y)
|
@@ -60,6 +92,12 @@ module AutoItX3
|
|
60
92
|
end
|
61
93
|
|
62
94
|
#Disables ("grays out") +self+.
|
95
|
+
#===Return value
|
96
|
+
#nil.
|
97
|
+
#===Raises
|
98
|
+
#[Au3Error] Failed to disable the control.
|
99
|
+
#===Example
|
100
|
+
# ctrl.disable
|
63
101
|
def disable
|
64
102
|
Control.functions[__method__] ||= AU3_Function.new("ControlDisable", 'SSS', 'L')
|
65
103
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide)
|
@@ -70,6 +108,12 @@ module AutoItX3
|
|
70
108
|
end
|
71
109
|
|
72
110
|
#Enables +self+ (i.e. make it accept user actions).
|
111
|
+
#===Return value
|
112
|
+
#nil.
|
113
|
+
#===Raises
|
114
|
+
#[Au3Error] Couldn't enable the control.
|
115
|
+
#===Example
|
116
|
+
# ctrl.enable
|
73
117
|
def enable
|
74
118
|
Control.functions[__method__] ||= AU3_Function.new("ControlEnable", 'SSS', 'L')
|
75
119
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide)
|
@@ -80,6 +124,12 @@ module AutoItX3
|
|
80
124
|
end
|
81
125
|
|
82
126
|
#Gives the input focus to +self+.
|
127
|
+
#===Return value
|
128
|
+
#nil.
|
129
|
+
#===Raises
|
130
|
+
#[Au3Error] Couldn't get the input focus.
|
131
|
+
#===Example
|
132
|
+
# ctrl.focus
|
83
133
|
def focus
|
84
134
|
Control.functions[__method__] ||= AU3_Functino.new("ControlFocus", 'SSS', 'L')
|
85
135
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide)
|
@@ -89,9 +139,15 @@ module AutoItX3
|
|
89
139
|
nil
|
90
140
|
end
|
91
141
|
|
92
|
-
#Returns the internal window handle of +self+.
|
142
|
+
#Returns the internal window handle of +self+.
|
143
|
+
#===Return value
|
144
|
+
#The handle of +self+ as a hexadecimal string.
|
145
|
+
#===Example
|
146
|
+
# hwnd = ctrl.handle.to_i(16)
|
147
|
+
#===Remarks
|
148
|
+
#The handle can be used in
|
93
149
|
#advanced window mode or directly in Win32 API calls (but you have
|
94
|
-
#to call #to_i on the string
|
150
|
+
#to call #to_i(16) on the string then).
|
95
151
|
def handle
|
96
152
|
Control.functions[__method__] ||= AU3_Function.new("ControlGetHandle", 'SSSPI')
|
97
153
|
buffer = " " * BUFFER_SIZE
|
@@ -101,8 +157,13 @@ module AutoItX3
|
|
101
157
|
buffer.normal.strip
|
102
158
|
end
|
103
159
|
|
104
|
-
#
|
105
|
-
|
160
|
+
#Gets the control's bounding rectangle.
|
161
|
+
#===Return value
|
162
|
+
#A 4-element array of form <tt>[ x , y , width , height ]</tt>.
|
163
|
+
#===Raises
|
164
|
+
#[Au3Error] Control or window not found.
|
165
|
+
#===Example
|
166
|
+
# p ctrl.rect #=> [66, 72, 297, 17]
|
106
167
|
def rect
|
107
168
|
Control.functions[:c_x] ||= AU3_Function.new("ControlGetPosX", 'SSS', 'L')
|
108
169
|
Control.functions[:c_y] ||= AU3_Function.new("ControlGetPosY", 'SSS', 'L')
|
@@ -121,6 +182,12 @@ module AutoItX3
|
|
121
182
|
end
|
122
183
|
|
123
184
|
#Returns the +self+'s text.
|
185
|
+
#===Return value
|
186
|
+
#The text value of +self+.
|
187
|
+
#===Raises
|
188
|
+
#[Au3Error] Control or window not found.
|
189
|
+
#===Example
|
190
|
+
# puts ctrl.text #=> regedit
|
124
191
|
def text
|
125
192
|
Control.functions[__method__] ||= AU3_Function.new("ControlGetText", 'SSSPI')
|
126
193
|
buffer = " " * BUFFER_SIZE
|
@@ -131,6 +198,13 @@ module AutoItX3
|
|
131
198
|
end
|
132
199
|
|
133
200
|
#Hides +self+.
|
201
|
+
#===Return value
|
202
|
+
#nil.
|
203
|
+
#===Example
|
204
|
+
# ctrl.hide
|
205
|
+
#===Remarks
|
206
|
+
#"Hidings" means to make a control completely invisible. If you just want it to
|
207
|
+
#refuse user input, use #disable.
|
134
208
|
def hide
|
135
209
|
Control.functions[__method__] ||= AU3_Function.new("ControlHide", 'SSS', 'L')
|
136
210
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide)
|
@@ -139,6 +213,22 @@ module AutoItX3
|
|
139
213
|
end
|
140
214
|
|
141
215
|
#Moves a control and optionally resizes it.
|
216
|
+
#===Parameters
|
217
|
+
#[+x+] The goal X coordinate.
|
218
|
+
#[+y+] The goal Y coordinate.
|
219
|
+
#[+width+] (-1) The goal width.
|
220
|
+
#[+height+] (-1) The goal height.
|
221
|
+
#===Return value
|
222
|
+
#nil.
|
223
|
+
#===Raises
|
224
|
+
#[Au3Error] Control or window not found.
|
225
|
+
#===Example
|
226
|
+
# ctrl.move(100, 100)
|
227
|
+
# #Move to (100|100) and resize
|
228
|
+
# ctrl.move(100, 100, 500, 500)
|
229
|
+
#===Remarks
|
230
|
+
#If you move or resize a control, the visually shown control may not change, but if you try to
|
231
|
+
#click on it after moving it away, you will get to know that it isn't there anymore.
|
142
232
|
def move(x, y, width = -1, height = -1)
|
143
233
|
Control.functions[__method__] ||= AU3_Function.new("ControlMove", 'SSSLLLL', 'L')
|
144
234
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide, x, y, width, height)
|
@@ -146,9 +236,21 @@ module AutoItX3
|
|
146
236
|
nil
|
147
237
|
end
|
148
238
|
|
149
|
-
#Simulates user input to a control.
|
150
|
-
|
151
|
-
#
|
239
|
+
#Simulates user input to a control.
|
240
|
+
#===Parameters
|
241
|
+
#[+str+] The input string to simulate.
|
242
|
+
#[+flag+] (0) If set to 1, escape sequences in braces { and } are ignored.
|
243
|
+
#===Return value
|
244
|
+
#nil.
|
245
|
+
#===Raises
|
246
|
+
#[Au3Error] Control or window not found.
|
247
|
+
#===Example
|
248
|
+
# #Send some keystrokes
|
249
|
+
# ctrl.send_keys("Abc")
|
250
|
+
# #Send some keys with escape sequences
|
251
|
+
# ctrl.send_keys("Ab{ESC}c")
|
252
|
+
# #Ignore the escape sequences
|
253
|
+
# ctrl.send_keys("Ab{ESC}c", 1)
|
152
254
|
def send_keys(str, flag = 0)
|
153
255
|
Control.functions[__method__] ||= AU3_Function.new("ControlSend", 'SSSSI', 'L')
|
154
256
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide, str.wide, flag)
|
@@ -157,6 +259,18 @@ module AutoItX3
|
|
157
259
|
end
|
158
260
|
|
159
261
|
#Sets the text of a control directly.
|
262
|
+
#===Parameters
|
263
|
+
#[+text+] The text to set.
|
264
|
+
#===Return value
|
265
|
+
#The +text+ argument.
|
266
|
+
#===Raises
|
267
|
+
#[Au3Error] Control or window not found.
|
268
|
+
#===Example
|
269
|
+
# ctrl.text = "My awesome text"
|
270
|
+
#===Remarks
|
271
|
+
#The difference to #send_keys is that some controls doesn't allow
|
272
|
+
#the user to type text into (labels for example). These control's text
|
273
|
+
#can be set by using this method, but note that escape sequences aren't supported here.
|
160
274
|
def text=(text)
|
161
275
|
Control.functions[__method__] ||= AU3_Function.new("ControlSetText", 'SSSS', 'L')
|
162
276
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide, text.wide)
|
@@ -165,6 +279,12 @@ module AutoItX3
|
|
165
279
|
end
|
166
280
|
|
167
281
|
#Shows a hidden control.
|
282
|
+
#===Return value
|
283
|
+
#nil.
|
284
|
+
#===Example
|
285
|
+
# ctrl.show
|
286
|
+
#===Remarks
|
287
|
+
#This doesn't enable user input, use #enable for that purpose.
|
168
288
|
def show
|
169
289
|
Control.functions[__method__] ||= AU3_Function.new("ControlShow", 'SSS', 'L')
|
170
290
|
res = Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide)
|
@@ -184,17 +304,38 @@ module AutoItX3
|
|
184
304
|
end
|
185
305
|
|
186
306
|
#Returns wheather or not a control is visible.
|
307
|
+
#===Return value
|
308
|
+
#true or false.
|
309
|
+
#===Raises
|
310
|
+
#[Au3Error] Control or window not found.
|
311
|
+
#===Example
|
312
|
+
# p ctrl.visible? #=> true
|
313
|
+
# ctrl.hide
|
314
|
+
# p ctrl.visible? #=> false
|
315
|
+
# ctrl.show
|
316
|
+
# p ctrl.visible #=> true
|
187
317
|
def visible?
|
188
318
|
send_command_to_control("IsVisible").to_i == 1
|
189
319
|
end
|
190
320
|
|
191
321
|
#Returns true if a control can interact with the user (i.e. it's not "grayed out").
|
322
|
+
#===Return value
|
323
|
+
#true or false.
|
324
|
+
#===Raises
|
325
|
+
#[Au3Error] Control or window not found.
|
326
|
+
#===Example
|
327
|
+
# p ctrl.enabled? #=> true
|
328
|
+
# ctrl.disable
|
329
|
+
# p ctrl.enabled? #=> false
|
330
|
+
# ctrl.enable
|
331
|
+
# p ctrl.enabled? #=> true
|
192
332
|
def enabled?
|
193
333
|
send_command_to_control("IsEnabled").to_i == 1
|
194
334
|
end
|
195
335
|
|
196
336
|
private
|
197
337
|
|
338
|
+
#Raises an error message saying that the window or the control wasn't found.
|
198
339
|
def raise_unfound
|
199
340
|
raise(Au3Error, "The control '#{@c_id}' was not found in the window '#{@title}' (or the window was not found)!", caller)
|
200
341
|
end
|
@@ -213,6 +354,15 @@ module AutoItX3
|
|
213
354
|
#Adds an entry to an existing combo or list box.
|
214
355
|
#If you use the << form, you can do a chain call like:
|
215
356
|
# ctrl << "a" << "b" << "c"
|
357
|
+
#===Parameters
|
358
|
+
#[+string+] The string to append.
|
359
|
+
#===Return value
|
360
|
+
#The appended string or +self+, in the case of the operator form.
|
361
|
+
#===Raises
|
362
|
+
#[Au3Error] Control or window not found.
|
363
|
+
#===Example
|
364
|
+
# list.add_item("my_item")
|
365
|
+
# list << "my_item" << "my_second_item"
|
216
366
|
def add_item(string)
|
217
367
|
send_command_to_control("AddString", string)
|
218
368
|
string
|
@@ -223,32 +373,67 @@ module AutoItX3
|
|
223
373
|
self
|
224
374
|
end
|
225
375
|
|
226
|
-
#
|
376
|
+
#Deletes an item.
|
377
|
+
#===Parameters
|
378
|
+
#[+item_number+] The 0-based index of the item to delete.
|
379
|
+
#===Return value
|
380
|
+
#Unknown.
|
381
|
+
#===Raises
|
382
|
+
#[Au3Error] Control or window not found.
|
383
|
+
#===Example
|
384
|
+
# list.delete(0)
|
227
385
|
def delete(item_number)
|
228
386
|
send_command_to_control("DelString", item.to_s).to_i
|
229
387
|
end
|
230
388
|
|
231
|
-
#Finds the item number of +item+ in +self+.
|
389
|
+
#Finds the item number (= 0-based index) of +item+ in +self+.
|
390
|
+
#===Parameters
|
391
|
+
#[+item+] The item to look for.
|
392
|
+
#===Return value
|
393
|
+
#Unknown.
|
394
|
+
#===Raises
|
395
|
+
#[Au3Error] Control or window not found.
|
396
|
+
#===Example
|
397
|
+
# p ctrl.find("my_item") #=> 3
|
232
398
|
def find(item)
|
233
399
|
send_command_to_control("FindString", item).to_i
|
234
400
|
end
|
235
401
|
|
236
402
|
#Sets the current selection of a combo box to item +num+.
|
237
|
-
|
238
|
-
#of
|
403
|
+
#===Parameters
|
404
|
+
#[+num+] The index of the item to set the selection to.
|
405
|
+
#===Return value
|
406
|
+
#+num+.
|
407
|
+
#===Raises
|
408
|
+
#[Au3Error] Index is out of range or the control or the window wasn't fond.
|
409
|
+
#===Example
|
410
|
+
# ctrl.current_selection = 3
|
239
411
|
def current_selection=(num)
|
240
412
|
send_command_to_control("SetCurrentSelection", num.to_i)
|
241
413
|
num
|
242
414
|
end
|
243
415
|
|
244
416
|
#Sets +self+'s selection to the first occurence of +str+.
|
245
|
-
|
417
|
+
#===Parameters
|
418
|
+
#[+str+] The string to select.
|
419
|
+
#===Return value
|
420
|
+
#+str+.
|
421
|
+
#===Raises
|
422
|
+
#[Au3Error] Couldn't find the string, the control or the window.
|
423
|
+
#===Example
|
424
|
+
# ctrl.select_string("my_string")
|
246
425
|
def select_string(str)
|
247
426
|
send_command_to_control("SelectString", str)
|
248
427
|
string
|
249
428
|
end
|
250
429
|
|
251
430
|
#Returns the currently selected string.
|
431
|
+
#===Return value
|
432
|
+
#The currently selected string.
|
433
|
+
#===Raises
|
434
|
+
#[Au3Error] Control or window not found.
|
435
|
+
#===Example
|
436
|
+
# p ctrl.current_selection #=> "my_string"
|
252
437
|
def current_selection
|
253
438
|
send_command_to_control("GetCurrentSelection")
|
254
439
|
end
|
@@ -261,6 +446,12 @@ module AutoItX3
|
|
261
446
|
class ComboBox < ListBox
|
262
447
|
|
263
448
|
#Drops down a combo box.
|
449
|
+
#===Return value
|
450
|
+
#Unknown.
|
451
|
+
#===Raises
|
452
|
+
#[Au3Error] Control or window not found.
|
453
|
+
#===Example
|
454
|
+
# box.drop
|
264
455
|
def drop
|
265
456
|
send_command_to_control("ShowDropDown")
|
266
457
|
end
|
@@ -270,6 +461,10 @@ module AutoItX3
|
|
270
461
|
# close
|
271
462
|
#
|
272
463
|
#Undrops or closes a combo box.
|
464
|
+
#===Return value
|
465
|
+
#Unknown.
|
466
|
+
#===Raises
|
467
|
+
#[Au3Error] Control or window not found.
|
273
468
|
def undrop
|
274
469
|
send_command_to_control("HideDropDown")
|
275
470
|
end
|
@@ -279,21 +474,45 @@ module AutoItX3
|
|
279
474
|
|
280
475
|
#A button is a control on which you can click and than something happens.
|
281
476
|
#Even if that's quite correct, that isn't all: check and radio boxes
|
282
|
-
#are handled by Windows as buttons, so they fall into the scope of this class.
|
477
|
+
#are handled by Windows as buttons as well, so they fall into the scope of this class.
|
283
478
|
class Button < Control
|
284
479
|
|
285
480
|
#Returns wheather +self+ is checked or not.
|
286
|
-
|
481
|
+
#===Return value
|
482
|
+
#true or false.
|
483
|
+
#===Raises
|
484
|
+
#[Au3Error] Control or window not found.
|
485
|
+
#===Example
|
486
|
+
# p ctrl.checked? #=> false
|
487
|
+
# ctrl.check
|
488
|
+
# p ctrl.checked? #=> true
|
489
|
+
#===Remarks
|
490
|
+
#This method is only useful for radio and check buttons.
|
287
491
|
def checked?
|
288
|
-
send_command_to_control("IsChecked") == 1
|
492
|
+
send_command_to_control("IsChecked") == "1"
|
289
493
|
end
|
290
494
|
|
291
495
|
#Checks +self+ if it's a radio or check button.
|
496
|
+
#===Return value
|
497
|
+
#Unknown.
|
498
|
+
#===Raises
|
499
|
+
#[Au3Error] Control or window not found.
|
500
|
+
#===Example
|
501
|
+
# ctrl.check
|
502
|
+
#===Rmarks
|
503
|
+
#Only useful for radio and check buttons. If you try to do this on a regular button,
|
504
|
+
#it's like you clicked it.
|
292
505
|
def check
|
293
506
|
send_command_to_control("Check")
|
294
507
|
end
|
295
508
|
|
296
509
|
#Unchecks +self+ if it's a radio or check button.
|
510
|
+
#===Return value
|
511
|
+
#Unknown.
|
512
|
+
#===Raises
|
513
|
+
#[Au3Error] Control or window not found.
|
514
|
+
#===Example
|
515
|
+
# ctrl.uncheck
|
297
516
|
def uncheck
|
298
517
|
send_command_to_control("UnCheck")
|
299
518
|
end
|
@@ -304,8 +523,13 @@ module AutoItX3
|
|
304
523
|
#type text. For example, notepad consists mainly of a big edit control.
|
305
524
|
class Edit < Control
|
306
525
|
|
307
|
-
#Returns the current caret position
|
308
|
-
|
526
|
+
#Returns the current caret position.
|
527
|
+
#===Return value
|
528
|
+
#A 2-element array of form <tt>[line, column]</tt>. Numbering starts with 1.
|
529
|
+
#===Raises
|
530
|
+
#[Au3Error] Control or window not found.
|
531
|
+
#===Example
|
532
|
+
# p edit.caret_pos #=> [1, 1]
|
309
533
|
def caret_pos
|
310
534
|
x = send_command_to_control("GetCurrentLine").to_i
|
311
535
|
y = send_command_to_control("GetCurrentCol").to_i
|
@@ -313,16 +537,39 @@ module AutoItX3
|
|
313
537
|
end
|
314
538
|
|
315
539
|
#Returns the number of lines in +self+.
|
540
|
+
#===Return value
|
541
|
+
#The number of lines.
|
542
|
+
#===Raises
|
543
|
+
#[Au3Error] Control or window not found.
|
544
|
+
#===Example
|
545
|
+
# p edit.lines #=> 3
|
316
546
|
def lines
|
317
547
|
send_command_to_control("GetLineCount").to_i
|
318
548
|
end
|
319
549
|
|
320
550
|
#Returns the currently selected text.
|
551
|
+
#===Return value
|
552
|
+
#The currently selected text selection.
|
553
|
+
#===Example
|
554
|
+
# p edit.selected_text #=> "I love Ruby!"
|
555
|
+
#===Remarks
|
556
|
+
#Be careful with the encoding of the returned text. It's likely that
|
557
|
+
#you have to do a force_encoding on it, since there isn't any guarantee in
|
558
|
+
#which encoding a window returns it's contents.
|
321
559
|
def selected_text
|
322
560
|
send_command_to_control("GetSelected")
|
323
561
|
end
|
324
562
|
|
325
563
|
#"Pastes" +str+ at +self+'s current caret position.
|
564
|
+
#===Parameters
|
565
|
+
#[+str+] The text to paste.
|
566
|
+
#===Return value
|
567
|
+
#Unknown.
|
568
|
+
#===Example
|
569
|
+
# edit.paste("My text")
|
570
|
+
#===Remarks
|
571
|
+
#In contrast to #selected_text, the window should receive the
|
572
|
+
#text correctly, since AutoItX3 only accepts UTF-16LE-encoded strings.
|
326
573
|
def paste(str)
|
327
574
|
send_command_to_control("EditPaste", str)
|
328
575
|
end
|
@@ -335,19 +582,35 @@ module AutoItX3
|
|
335
582
|
class TabBook < Control
|
336
583
|
|
337
584
|
#Returns the currently shown tab.
|
585
|
+
#===Return value
|
586
|
+
#The number of the currently shown tab, starting with 1.
|
587
|
+
#===Raises
|
588
|
+
#[Au3Error] Control or window not found.
|
589
|
+
#===Example
|
590
|
+
# p tab.current #=> 2
|
338
591
|
def current
|
339
592
|
send_command_to_control("CurrentTab").to_i
|
340
593
|
end
|
341
594
|
|
342
|
-
#Shows the tab right to the current one
|
343
|
-
|
595
|
+
#Shows the tab right to the current one.
|
596
|
+
#===Return value
|
597
|
+
#Returns the number of the now shown tab, starting with 1.
|
598
|
+
#===Raises
|
599
|
+
#[Au3Error] Control or window not found.
|
600
|
+
#===Example
|
601
|
+
# tab.right #| 3
|
344
602
|
def right
|
345
603
|
send_command_to_control("TabRight")
|
346
604
|
current
|
347
605
|
end
|
348
606
|
|
349
|
-
#Shows the tab left to the current one
|
350
|
-
|
607
|
+
#Shows the tab left to the current one.
|
608
|
+
#===Return value
|
609
|
+
#Returns the number of the now shown tab, starting with 1.
|
610
|
+
#===Raises
|
611
|
+
#[Au3Error] Control or window not found.
|
612
|
+
#===Example
|
613
|
+
# tab.left #| 1
|
351
614
|
def left
|
352
615
|
send_command_to_control("TabLeft")
|
353
616
|
current
|
@@ -356,7 +619,8 @@ module AutoItX3
|
|
356
619
|
end
|
357
620
|
|
358
621
|
#A list view is a list which can contain many different
|
359
|
-
#columns of data.
|
622
|
+
#columns of data. For example, the Windows Explorer
|
623
|
+
#uses this control.
|
360
624
|
class ListView < Control
|
361
625
|
|
362
626
|
#Ordinary list view
|
@@ -379,12 +643,29 @@ module AutoItX3
|
|
379
643
|
end
|
380
644
|
|
381
645
|
#Deselects the given item(s).
|
646
|
+
#===Parameters
|
647
|
+
#[+from+] Either the index of the item to deselect or the start of the item list to deselect. 0-based.
|
648
|
+
#[+to+] (<tt>""</tt>) The end of the item list to deselect. 0-based.
|
649
|
+
#===Return value
|
650
|
+
#Unknown.
|
651
|
+
#===Raises
|
652
|
+
#[Au3Error] Control or window not found.
|
382
653
|
def deselect(from, to = "")
|
383
654
|
send_command_to_list_view("DeSelect", from, to)
|
384
655
|
end
|
385
656
|
|
386
|
-
#Searches for +string+ and +sub_item+ in +self
|
387
|
-
|
657
|
+
#Searches for +string+ and +sub_item+ in +self+.
|
658
|
+
#===Parameters
|
659
|
+
#[+string+] The string to look for.
|
660
|
+
#[+sub_item+] (<tt>""</tt>) The "colum" to look in. A 0-based integer index.
|
661
|
+
#===Return value
|
662
|
+
#Returns the index of the found list item or false if it isn't found.
|
663
|
+
#===Raises
|
664
|
+
#[Au3Error] Control or window not found.
|
665
|
+
#===Example
|
666
|
+
# p ctrl.find("file1.rb") #=> 3
|
667
|
+
# p ctrl.find("15 KB", 3) #=> 2
|
668
|
+
# p ctrl.find("nonexistant") #=> false
|
388
669
|
def find(string, sub_item = "")
|
389
670
|
res = send_command_to_list_view("FindItem", string, sub_item).to_i
|
390
671
|
if res == -1
|
@@ -400,24 +681,47 @@ module AutoItX3
|
|
400
681
|
# length ==> anInteger
|
401
682
|
#
|
402
683
|
#Returns the number of items in +self+.
|
684
|
+
#===Return value
|
685
|
+
#The number of items in +self+.
|
686
|
+
#===Raises
|
687
|
+
#[Au3Error] Control or window not found.
|
688
|
+
#===Example
|
689
|
+
# p ctrl.item_count #=> 9
|
403
690
|
def item_count
|
404
691
|
send_command_to_list_view("GetItemCount").to_i
|
405
692
|
end
|
406
693
|
alias size item_count
|
407
694
|
alias length item_count
|
408
695
|
|
409
|
-
#Returns the inices of the selected items
|
410
|
-
|
696
|
+
#Returns the inices of the selected items.
|
697
|
+
#===Return value
|
698
|
+
#An array containg the indices of the selected items which is empty if none is selected.
|
699
|
+
#===Raises
|
700
|
+
#[Au3Error] Control or window not found.
|
701
|
+
#===Example
|
702
|
+
# p ctrl.selected #=> [3, 4, 5]
|
411
703
|
def selected
|
412
|
-
send_command_to_list_view("GetSelected", 1).split("|")
|
704
|
+
send_command_to_list_view("GetSelected", 1).split("|").map(&:to_i)
|
413
705
|
end
|
414
706
|
|
415
707
|
#Returns the number of selected items.
|
708
|
+
#===Return value
|
709
|
+
#The number of items selected.
|
710
|
+
#===Raises
|
711
|
+
#[Au3Error] Control or window not found.
|
712
|
+
#===Example
|
713
|
+
# p ctrl.num_selected #=> 3
|
416
714
|
def num_selected
|
417
715
|
send_command_to_list_view("GetSelectedCount").to_i
|
418
716
|
end
|
419
717
|
|
420
718
|
#Returns the number of subitems in +self+.
|
719
|
+
#===Return value
|
720
|
+
#An integer that indicates how many "columns" the list view has.
|
721
|
+
#===Raises
|
722
|
+
#[Au3Error] Control or window not found.
|
723
|
+
#===Example
|
724
|
+
# p ctrl.num_subitems #=> 4
|
421
725
|
def num_subitems
|
422
726
|
send_command_to_list_view("GetSubItemCount").to_i
|
423
727
|
end
|
@@ -427,22 +731,67 @@ module AutoItX3
|
|
427
731
|
# AutoItX3::ListView#[ item [, subitem ] ] ==> aString
|
428
732
|
#
|
429
733
|
#Returns the text at the given position.
|
734
|
+
#===Parameters
|
735
|
+
#[+item+] The "row" to look in. 0-based integer.
|
736
|
+
#[+subitem+] (<tt>""</tt>) The "colum" to look in. 0-based integer.
|
737
|
+
#===Return value
|
738
|
+
#The text at the given position.
|
739
|
+
#===Raises
|
740
|
+
#[Au3Error] Control or window not found.
|
741
|
+
#===Example
|
742
|
+
# p ctrl.text_at(2, 3) #=> "6 KB"
|
743
|
+
#===Remarks
|
744
|
+
#Don't make any assumptions about the encoding or event the content
|
745
|
+
#of a list box item. For example, a date field of the Windows Explorer
|
746
|
+
#comes out like this:
|
747
|
+
# p ctrl.text_at(2, 1) #=> "ÔÇÄ10.ÔÇÄ05.ÔÇÄ2010 ÔÇÅÔÇÄ16:53"
|
748
|
+
#which is probably not what you thought, since in the Explorer Window it's
|
749
|
+
#presented as:
|
750
|
+
# 10.05.2010 16:52
|
430
751
|
def text_at(item, subitem = "")
|
431
752
|
send_command_to_list_view("GetText", item, subitem)
|
432
753
|
end
|
433
754
|
alias [] text_at
|
434
755
|
|
435
756
|
#Returns wheather or not +item+ is selected.
|
757
|
+
#===Parameters
|
758
|
+
#[+item+] The 0-based index of the item to check.
|
759
|
+
#===Return value
|
760
|
+
#true or false.
|
761
|
+
#===Raises
|
762
|
+
#[Au3Error] Control or window not found.
|
763
|
+
#===Example
|
764
|
+
# p ctrl.selected?(3) #=> false
|
765
|
+
# p ctrl.selected?(7) #=> true
|
436
766
|
def selected?(item)
|
437
767
|
send_command_to_list_view("IsSelected", item).to_i == 1
|
438
768
|
end
|
439
769
|
|
440
770
|
#Selects the given item(s).
|
771
|
+
#===Parameters
|
772
|
+
#[+from+] The index where to start or the item to select. 0-based integer.
|
773
|
+
#[+to+] The index where to stop. 0-based integer.
|
774
|
+
#===Return value
|
775
|
+
#Unknown.
|
776
|
+
#===Raises
|
777
|
+
#[Au3Error] Control or window not found.
|
778
|
+
#===Example
|
779
|
+
# ctrl.select(3)
|
780
|
+
# ctrl.select(3, 5)
|
781
|
+
#===Remarks
|
782
|
+
#This method doesn't deselect anything. If you want an entire new selection,
|
783
|
+
#call #clear_selection before calling this method.
|
441
784
|
def select(from, to = "")
|
442
785
|
send_command_to_list_view("Select", from, to)
|
443
786
|
end
|
444
787
|
|
445
788
|
#Selects all items in +self+.
|
789
|
+
#===Return value
|
790
|
+
#Unknown.
|
791
|
+
#===Raises
|
792
|
+
#[Au3Error] Control or window not found.
|
793
|
+
#===Example
|
794
|
+
# ctrl.select_all
|
446
795
|
def select_all
|
447
796
|
send_command_to_list_view("SelectAll")
|
448
797
|
end
|
@@ -451,18 +800,39 @@ module AutoItX3
|
|
451
800
|
# AutoItX3::ListView#select_none ==> nil
|
452
801
|
#
|
453
802
|
#Clears the selection.
|
803
|
+
#===Return value
|
804
|
+
#Unknown.
|
805
|
+
#===Raises
|
806
|
+
#[Au3Error] Control or window not found.
|
807
|
+
#===Example
|
808
|
+
# ctrl.clear_selection
|
454
809
|
def clear_selection
|
455
810
|
send_command_to_list_view("SelectClear")
|
456
811
|
end
|
457
812
|
alias select_none clear_selection
|
458
813
|
|
459
814
|
#Inverts the selection.
|
815
|
+
#===Return value
|
816
|
+
#Unknown.
|
817
|
+
#===Raises
|
818
|
+
#[Au3Error] Control or window not found.
|
819
|
+
#===Example
|
820
|
+
# ctrl.invert_selection
|
821
|
+
#===Remarks
|
822
|
+
#This works even if nothing or everything is selected.
|
460
823
|
def invert_selection
|
461
824
|
send_command_to_list_view("SelectInvert")
|
462
825
|
end
|
463
826
|
|
464
|
-
#Changes the view of +self+.
|
465
|
-
|
827
|
+
#Changes the view of +self+.
|
828
|
+
#===Parameters
|
829
|
+
#[+view+] The view to change to. Possible values are the constants of the ListView class.
|
830
|
+
#===Return value
|
831
|
+
#Unknown.
|
832
|
+
#===Raises
|
833
|
+
#[Au3Error] Control or window not found.
|
834
|
+
#===Example
|
835
|
+
# ctrl.change_view(AutoItX3::ListView::LIST)
|
466
836
|
def change_view(view)
|
467
837
|
send_command_to_list_view("ViewChange", view)
|
468
838
|
end
|
@@ -471,6 +841,10 @@ module AutoItX3
|
|
471
841
|
|
472
842
|
#A TreeView is a control that shows a kind of expandable
|
473
843
|
#list, like the one displayed ont the left side in <tt>.chm</tt> files.
|
844
|
+
#
|
845
|
+
#The +item+ parameter of many methods in this class is a string of form
|
846
|
+
# "#index_0|#index_1|#index_2..."
|
847
|
+
#that describes where to find the item. See the #selected method for an example.
|
474
848
|
class TreeView < Control
|
475
849
|
|
476
850
|
#Sends +cmd+ to +self+. This method is only used internally.
|
@@ -478,38 +852,96 @@ module AutoItX3
|
|
478
852
|
Control.functions[__method__] ||= AU3_Function.new("ControlTreeView", 'SSSSSSPI')
|
479
853
|
buffer = " " * BUFFER_SIZE
|
480
854
|
buffer.wide!
|
481
|
-
Control.functions[__method__].call(@title.wide, @text.wide, @c_id.wide, command.wide, arg1.wide, arg2.wide, buffer, BUFFER_SIZE - 1)
|
855
|
+
Control.functions[__method__].call(@title.wide, @text.wide, @c_id.to_s.wide, command.to_s.wide, arg1.to_s.wide, arg2.to_s.wide, buffer, BUFFER_SIZE - 1)
|
482
856
|
raise(Au3Error, "Unknown error occured when sending '#{command}' to '#{@c_id}' in '#{@title}'! Maybe an invalid window?") if AutoItX3.last_error == 1
|
483
857
|
buffer.normal.strip
|
484
858
|
end
|
485
859
|
|
486
|
-
#Checks +item
|
860
|
+
#Checks +item+, if it supports that operation.
|
861
|
+
#===Parameters
|
862
|
+
#[+item+] The path of the item to check.
|
863
|
+
#===Return value
|
864
|
+
#Unknown.
|
865
|
+
#===Raises
|
866
|
+
#[Au3Error] Control or window not found.
|
867
|
+
#===Example
|
868
|
+
# ctrl.check("#0|#3|#7")
|
487
869
|
def check(item)
|
488
870
|
send_command_to_tree_view("Check", item)
|
489
871
|
end
|
490
872
|
|
491
873
|
#Collapses +item+ to hide its children.
|
874
|
+
#===Parameters
|
875
|
+
#[+item+] The path of the item to collapse.
|
876
|
+
#===Return value
|
877
|
+
#Unknown.
|
878
|
+
#===Raises
|
879
|
+
#[Au3Error] Control or window not found.
|
880
|
+
#===Example
|
881
|
+
# ctrl.collapse("#0")
|
492
882
|
def collapse(item)
|
493
883
|
send_command_to_tree_view("Collapse", item)
|
494
884
|
end
|
495
885
|
|
496
886
|
#Return wheather or not +item+ exists.
|
887
|
+
#===Parameters
|
888
|
+
#[+item+] The path of the item to check.
|
889
|
+
#===Return value
|
890
|
+
#true or false.
|
891
|
+
#===Raises
|
892
|
+
#[Au3Error] Control or window not found.
|
893
|
+
#===Example
|
894
|
+
# p ctrl.exists?("#0|#3") #=> true
|
895
|
+
# p ctrl.exists?("#1|#4") #=> false
|
497
896
|
def exists?(item)
|
498
897
|
send_command_to_tree_view("Exists", item).to_i == 1
|
499
898
|
end
|
500
899
|
|
501
900
|
#Expands +item+ to show its children.
|
901
|
+
#===Parameters
|
902
|
+
#[+item+] The path of the item to expand.
|
903
|
+
#===Return value
|
904
|
+
#Unknown.
|
905
|
+
#===Raises
|
906
|
+
#[Au3Error] Control or window not found.
|
907
|
+
#===Example
|
908
|
+
# ctrl.expand("#0|#3")
|
502
909
|
def expand(item)
|
503
910
|
send_command_to_tree_view("Expand", item)
|
504
911
|
end
|
505
912
|
|
506
913
|
#Returns the number of children of +item+.
|
914
|
+
#===Parameters
|
915
|
+
#[+item+] The path of the item to check.
|
916
|
+
#===Return value
|
917
|
+
#The number of subitems of that node.
|
918
|
+
#===Raises
|
919
|
+
#[Au3Error] Control or window not found.
|
920
|
+
#===Example
|
921
|
+
# p ctrl.num_subitems("#0") #=> 8
|
922
|
+
#===Remarks
|
923
|
+
#This method returns 0 if the item doesn't exist.
|
507
924
|
def num_subitems(item)
|
508
925
|
send_command_to_tree_view("GetItemCount", item).to_i
|
509
926
|
end
|
510
927
|
|
511
|
-
#Returns
|
512
|
-
|
928
|
+
#Returns where to find the selected item.
|
929
|
+
#===Parameters
|
930
|
+
#[+use_index+] (+false+) If this is true, you only get the last index.
|
931
|
+
#===Return value
|
932
|
+
#If +use_index+ is false, which is the default, you get a string back that describes
|
933
|
+
#where you find the currently selected item. The string is of form
|
934
|
+
# "#index_0|#index_1|#index_3..."
|
935
|
+
#for example
|
936
|
+
# "#0|#3|#0|#10|#1|#0"
|
937
|
+
#for the "ControlClick" item in the AutoItX help.
|
938
|
+
#Otherwise, if +use_index+ is false, you only get the last index of that chain, as an integer.
|
939
|
+
#===Raises
|
940
|
+
#[Au3Error] Control or window not found.
|
941
|
+
#===Example
|
942
|
+
#See <i>Return value</i>.
|
943
|
+
#===Remarks
|
944
|
+
#You can pass the result of this method directly to many methods of this class.
|
513
945
|
def selected(use_index = false)
|
514
946
|
result = send_command_to_tree_view("GetSelected", use_index ? 1 : 0)
|
515
947
|
return result.to_i if use_index
|
@@ -521,23 +953,58 @@ module AutoItX3
|
|
521
953
|
# [ item ] ==> aString
|
522
954
|
#
|
523
955
|
#Returns the text of +item+.
|
956
|
+
#===Parameters
|
957
|
+
#[+item+] The item to retrieve the text from.
|
958
|
+
#===Return value
|
959
|
+
#The text at the specified position.
|
960
|
+
#===Raises
|
961
|
+
#[Au3Error] Control or window not found.
|
962
|
+
#===Example
|
963
|
+
# p ctrl.text_at("#0|#3|#0|#10|#1|#0") #=> "ControlClick"
|
964
|
+
#===Remarks
|
965
|
+
#See #selected for an easy way of how to get the text of the currently selected item.
|
524
966
|
def text_at(item)
|
525
967
|
send_command_to_tree_view("GetText", item)
|
526
968
|
end
|
527
969
|
alias [] text_at
|
528
970
|
|
529
|
-
#Returns wheather or not +item+ is checked.
|
530
|
-
|
971
|
+
#Returns wheather or not +item+ is checked.
|
972
|
+
#===Parameters
|
973
|
+
#[+item+] The item to check.
|
974
|
+
#===Return value
|
975
|
+
#true or false.
|
976
|
+
#===Raises
|
977
|
+
#[Au3Error] Control or window not found.
|
978
|
+
#===Example
|
979
|
+
# p ctrl.checked?("#1|#2|#3") #=> true
|
980
|
+
#===Remarks
|
981
|
+
#This method always returns false for non-checkable items.
|
531
982
|
def checked?(item)
|
532
983
|
send_command_to_tree_view("IsChecked", item).to_i == 1
|
533
984
|
end
|
534
985
|
|
535
986
|
#Selects +item+.
|
987
|
+
#===Parameters
|
988
|
+
#[+item+] The item to select.
|
989
|
+
#===Return value
|
990
|
+
#Unknown.
|
991
|
+
#===Raises
|
992
|
+
#[Au3Error] Control or window not found.
|
993
|
+
#===Example
|
994
|
+
# ctrl.select("#1|#2")
|
536
995
|
def select(item)
|
537
996
|
send_command_to_tree_view("Select", item)
|
538
997
|
end
|
539
998
|
|
540
999
|
#Unchecks +item+ if it suports that operation (i.e. it's a checkbox).
|
1000
|
+
#===Parameters
|
1001
|
+
#[+item+] The item to uncheck.
|
1002
|
+
#===Return value
|
1003
|
+
#Unknown.
|
1004
|
+
#===Raises
|
1005
|
+
#[Au3Error] Control or Window not found.
|
1006
|
+
#===Example
|
1007
|
+
# ctrl.uncheck("#0|#3")
|
541
1008
|
def uncheck(item)
|
542
1009
|
send_command_to_tree_view("Uncheck", item)
|
543
1010
|
end
|