Class: AutoIt::Control

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeControl

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

#winObject (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



28
29
30
31
32
33
# File 'lib/autoit/control.rb', line 28

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

#get_text(title) ⇒ Object



35
36
37
# File 'lib/autoit/control.rb', line 35

def get_text(title)
  win.WinGetText(title)
end

#has_int?(title, value) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/autoit/control.rb', line 39

def has_int?(title, value)
  found = get_text title
  found.to_i == value
end

#has_text?(title, text) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/autoit/control.rb', line 44

def has_text?(title, text)
  found = get_text title
  found.to_s.chomp == text.to_s
end

#open_app(app) ⇒ Object



23
24
25
26
# File 'lib/autoit/control.rb', line 23

def open_app(app)
  raise "Parameter: '#{app}' is invalid!" if app.nil? || app.empty?
  execute { win.run app }
end

#win_close(title) ⇒ Object



19
20
21
# File 'lib/autoit/control.rb', line 19

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.



53
54
55
# File 'lib/autoit/control.rb', line 53

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

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/autoit/control.rb', line 62

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

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/autoit/control.rb', line 72

def window_exists?(title, text = '')
  sleep 3
  execute { win.WinExists(title, text) }
end