Class: AutoIt::Control
- Inherits:
-
Object
- Object
- AutoIt::Control
- Defined in:
- lib/autoit/control.rb
Overview
Class module to execute control commands on AutoIt DLL. Its possible to run native commands and some methods for object
Instance Attribute Summary collapse
-
#win ⇒ Object
readonly
Returns the value of attribute win.
Instance Method Summary collapse
- #click_on(title, id, text = nil) ⇒ Object
- #command(cmd, args = {}) ⇒ Object
- #command_validate(cmd, args = {}) ⇒ Object
-
#control_click(title, text, control, button, clicks, x, y) ⇒ Object
Sends a mouse click command to a given control.
-
#control_command_hide_drop_down(title, text, control) ⇒ Object
Undrops a ComboBox @param: title: The title of the window to access.
-
#control_command_select_string(title, text, control, string) ⇒ Object
Sets selection according to string in a ListBox or ComboBox @param: title: The title of the window to access.
-
#control_command_set_current_selection(title, text, control, occurrance) ⇒ Object
Sets selection to occurrence ref in a ListBox or ComboBox.
-
#control_command_show_drop_down(title, text, control) ⇒ Object
Drops a ComboBox @param: title: The title of the window to access.
-
#control_focus(title, text, control) ⇒ Object
Sets input focus to a given control on a window.
-
#control_set_text(title, text, control, value) ⇒ Object
Sets text of a control.
- #get_text(title) ⇒ Object
- #has_int?(title, value) ⇒ Boolean
- #has_text?(title, text) ⇒ Boolean
-
#initialize ⇒ Control
constructor
A new instance of Control.
- #open_app(app) ⇒ Object
-
#send(keys) ⇒ Object
Sends simulated keystrokes to the active window.
-
#win_activate(*args) ⇒ Object
Activates (gives focus to) a window.
- #win_close(title) ⇒ Object
-
#window_activate(title, text = nil) ⇒ Object
Use to activate an opened window title: The title/hWnd/class of the window to activate.
-
#window_active?(title, text = '') ⇒ Boolean
Check if a windows is active or not title: The title/hWnd/class of the window to activate.
-
#window_exists?(title, text = '') ⇒ Boolean
Check if a windows exists or not title: The title/hWnd/class of the window to activate.
Constructor Details
#initialize ⇒ Control
Returns a new instance of Control.
10 11 12 13 |
# File 'lib/autoit/control.rb', line 10 def initialize # dll = RUBY_PLATFORM.include? 'x64' ? a : b @win = WIN32OLE.new('AutoItX3.Control') end |
Instance Attribute Details
#win ⇒ Object (readonly)
Returns the value of attribute win.
8 9 10 |
# File 'lib/autoit/control.rb', line 8 def win @win end |
Instance Method Details
#click_on(title, id, text = nil) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/autoit/control.rb', line 32 def click_on(title, id, text = nil) execute do win.WinWaitActive(title, nil, 30) win.ControlClick(title, text, id) end end |
#command(cmd, args = {}) ⇒ Object
15 16 17 |
# File 'lib/autoit/control.rb', line 15 def command(cmd, args = {}) execute { win.send(cmd, *args) } end |
#command_validate(cmd, args = {}) ⇒ Object
19 20 21 |
# File 'lib/autoit/control.rb', line 19 def command_validate(cmd, args={}) execute_validate{win.send(cmd. *args)} end |
#control_click(title, text, control, button, clicks, x, y) ⇒ Object
Sends a mouse click command to a given control. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: controlID: The control to interact with. @param: button: The button to click, “left”, “right” or “middle”. @param: clicks: The number of times to click the mouse. Default is center. @param: x: The x position to click within the control. Default is center. @param: y: The y position to click within the control. Default is center. @return: True if success, false otherwise.
150 151 152 |
# File 'lib/autoit/control.rb', line 150 def control_click(title, text, control, , clicks, x, y) command_validate('ControlClick', [title, text, control, , clicks, x, y]) end |
#control_command_hide_drop_down(title, text, control) ⇒ Object
Undrops a ComboBox @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with.
126 127 128 |
# File 'lib/autoit/control.rb', line 126 def control_command_hide_drop_down(title, text, control) command 'ControlCommand', [title, text, control, 'HideDropDown', ''] end |
#control_command_select_string(title, text, control, string) ⇒ Object
Sets selection according to string in a ListBox or ComboBox @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: string: The string.
110 111 112 |
# File 'lib/autoit/control.rb', line 110 def control_command_select_string(title, text, control, string) command 'ControlCommand', [title, text, control, 'SelectString', string] end |
#control_command_set_current_selection(title, text, control, occurrance) ⇒ Object
Sets selection to occurrence ref in a ListBox or ComboBox. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: occurrance: the value.
159 160 161 |
# File 'lib/autoit/control.rb', line 159 def control_command_set_current_selection(title, text, control, occurrance) command('ControlCommand', [title, text, control, 'SetCurrentSelection', occurrance]) end |
#control_command_show_drop_down(title, text, control) ⇒ Object
Drops a ComboBox @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with.
118 119 120 |
# File 'lib/autoit/control.rb', line 118 def control_command_show_drop_down(title, text, control) command 'ControlCommand', [title, text, control, 'ShowDropDown', ''] end |
#control_focus(title, text, control) ⇒ Object
Sets input focus to a given control on a window. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with.
95 96 97 |
# File 'lib/autoit/control.rb', line 95 def control_focus(title, text, control) command 'ControlFocus', [title, text, control] end |
#control_set_text(title, text, control, value) ⇒ Object
Sets text of a control. Sends a string of characters to a control. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: string: The string.
137 138 139 |
# File 'lib/autoit/control.rb', line 137 def control_set_text(title, text, control, value) command_validate'ControlSetText', [title, text, control, value] end |
#get_text(title) ⇒ Object
39 40 41 |
# File 'lib/autoit/control.rb', line 39 def get_text(title) win.WinGetText(title) end |
#has_int?(title, value) ⇒ Boolean
43 44 45 46 |
# File 'lib/autoit/control.rb', line 43 def has_int?(title, value) found = get_text title found.to_i == value end |
#has_text?(title, text) ⇒ Boolean
48 49 50 51 |
# File 'lib/autoit/control.rb', line 48 def has_text?(title, text) found = get_text title found.to_s.chomp == text.to_s end |
#open_app(app) ⇒ Object
27 28 29 30 |
# File 'lib/autoit/control.rb', line 27 def open_app(app) raise "Parameter: '#{app}' is invalid!" if app.nil? || app.empty? execute { win.run app } end |
#send(keys) ⇒ Object
Sends simulated keystrokes to the active window. keys: The sequence of keys to send.
101 102 103 |
# File 'lib/autoit/control.rb', line 101 def send keys command 'Send', [keys, 1] end |
#win_activate(*args) ⇒ Object
Activates (gives focus to) a window. @param: title: The title/hWnd/class of the window to activate.
83 84 85 86 87 88 89 |
# File 'lib/autoit/control.rb', line 83 def win_activate(*args) if args == 1 command'WinActivate', [args[0]] elsif args == 2 command'WinActivate', [args[0], args[1]] end end |
#win_close(title) ⇒ Object
23 24 25 |
# File 'lib/autoit/control.rb', line 23 def win_close(title) execute { win.WinClose title } end |
#window_activate(title, text = nil) ⇒ Object
Use to activate an opened window title: The title/hWnd/class of the window to activate. text: [optional] The text of the window to activate. Default is an empty string.
57 58 59 |
# File 'lib/autoit/control.rb', line 57 def window_activate(title, text = nil) win.WinActivate(title, text).nil? end |
#window_active?(title, text = '') ⇒ Boolean
Check if a windows is active or not title: The title/hWnd/class of the window to activate. text: [optional] The text of the window to activate. Default is an empty string. return: true or false
66 67 68 69 |
# File 'lib/autoit/control.rb', line 66 def window_active?(title, text = '') sleep 3 execute { win.WinActive(title, text) } end |
#window_exists?(title, text = '') ⇒ Boolean
Check if a windows exists or not title: The title/hWnd/class of the window to activate. text: [optional] The text of the window to activate. Default is an empty string. return: true or false
76 77 78 79 |
# File 'lib/autoit/control.rb', line 76 def window_exists?(title, text = '') sleep 3 execute { win.WinExists(title, text) } end |