class AutoIt::Control

Class module to execute control commands on AutoIt DLL. Its possible to run native commands and some methods for object

Attributes

win[R]

Public Class Methods

new() click to toggle source
# File lib/autoit/control.rb, line 10
def initialize
  # dll = RUBY_PLATFORM.include? 'x64' ? a : b
  @win = WIN32OLE.new('AutoItX3.Control')
end

Public Instance Methods

click_on(title, id, text = nil) click to toggle source
# 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 = {}) click to toggle source
# File lib/autoit/control.rb, line 15
def command(cmd, args = {})
  execute { win.send(cmd, *args) }
end
command_validate(cmd, args={}) click to toggle source
# 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) click to toggle source

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.

# File lib/autoit/control.rb, line 150
def control_click(title, text, control, button, clicks, x, y)
  command_validate('ControlClick', [title, text, control, button, clicks, x, y])
end
control_command_hide_drop_down(title, text, control) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

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.

# 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) click to toggle source

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. @return True if success, false otherwise

# 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) click to toggle source
# File lib/autoit/control.rb, line 39
def get_text(title)
  win.WinGetText(title)
end
has_int?(title, value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Sends simulated keystrokes to the active window. keys: The sequence of keys to send.

# File lib/autoit/control.rb, line 101
def send keys
  command 'Send', [keys, 1]
end
win_activate(*args) click to toggle source

Activates (gives focus to) a window. @param: title: The title/hWnd/class of the window to activate.

# 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) click to toggle source
# File lib/autoit/control.rb, line 23
def win_close(title)
  execute { win.WinClose title }
end
window_activate(title, text = nil) click to toggle source

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.

# File lib/autoit/control.rb, line 57
def window_activate(title, text = nil)
  win.WinActivate(title, text).nil?
end
window_active?(title, text = '') click to toggle source

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

# File lib/autoit/control.rb, line 66
def window_active?(title, text = '')
  sleep 3
  execute { win.WinActive(title, text) }
end
window_exists?(title, text = '') click to toggle source

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

# File lib/autoit/control.rb, line 76
def window_exists?(title, text = '')
  sleep 3
  execute { win.WinExists(title, text) }
end

Private Instance Methods

execute() { || ... } click to toggle source
# File lib/autoit/control.rb, line 165
def execute
  yield
end
execute_validate() { |> 0| ... } click to toggle source
# File lib/autoit/control.rb, line 169
def execute_validate
  yield > 0
end