Module: AutoItFFI::AutoIt

Extended by:
FFI::Library
Defined in:
lib/autoit-ffi.rb

Constant Summary collapse

AU3_INTDEFAULT =

“Default” value for some int parameters (largest negative number)

-2147483647
# Used when constructing strings consumed by AutoIt
UTF_16LE_NULL =

Used when constructing strings consumed by AutoIt

"\0".encode("UTF-16LE")

Class Method Summary collapse

Class Method Details

.admin?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/autoit-ffi.rb', line 32

def admin?
  self.AU3_IsAdmin == 1
end

.auto_it_set_option(option, value) ⇒ Object



28
29
30
# File 'lib/autoit-ffi.rb', line 28

def auto_it_set_option(option, value)
  self.AU3_AutoItSetOption(to_utf16(option), value.to_i)
end

.block_input(flag) ⇒ Object



36
37
38
39
# File 'lib/autoit-ffi.rb', line 36

def block_input(flag)
  flag_int = flag ? 1 : 0
  self.AU3_BlockInput(flag_int)
end

.cd_tray(drive, action) ⇒ Object



41
42
43
44
# File 'lib/autoit-ffi.rb', line 41

def cd_tray(drive, action)
  result = self.AU3_CDTray(to_utf16(drive), to_utf16(action))
  result == 1
end

.clip_getObject

TODO: currently this method allocates a buffer that can hold 10000 utf16 characters to which the clipboard data is read to. A better approach would be to first query the size of the clipboard and allocate a buffer that fits that size. Note that the program will crash if there is more than 10000 characters in the clipboard.



52
53
54
55
56
57
# File 'lib/autoit-ffi.rb', line 52

def clip_get
  buffer = FFI::MemoryPointer.new(:uint16, 10000, true) # allocate 20000 bytes and zero out the memory.
  self.AU3_ClipGet(buffer, 10000)
  clipboard_data = buffer.read_string(buffer.size)
  clipboard_data.force_encoding("UTF-16LE").encode("UTF-8").rstrip
end

.control_click(title, text, control, button, num_clicks, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/autoit-ffi.rb', line 59

def control_click(title, text, control, button, num_clicks, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT) 
  self.AU3_ControlClick(to_utf16(title),
                        to_utf16(text),
                        to_utf16(control),
                        to_utf16(button),
                        num_clicks.to_i,
                        x.to_i,
                        y.to_i)
end

.errorObject



24
25
26
# File 'lib/autoit-ffi.rb', line 24

def error
  self.AU3_error
end

.get_mouse_pos_xObject



73
74
75
# File 'lib/autoit-ffi.rb', line 73

def get_mouse_pos_x
  self.AU3_MouseGetPosX
end

.get_mouse_pos_yObject



77
78
79
# File 'lib/autoit-ffi.rb', line 77

def get_mouse_pos_y
  self.AU3_MouseGetPosY
end

.mouse_wheel(direction, clicks) ⇒ Object



89
90
91
# File 'lib/autoit-ffi.rb', line 89

def mouse_wheel(direction, clicks)
  self.AU3_MouseWheel(to_utf16(direction), clicks.to_i)
end

.move_mouse(x, y, speed = 10) ⇒ Object



69
70
71
# File 'lib/autoit-ffi.rb', line 69

def move_mouse(x, y, speed = 10)
  self.AU3_MouseMove(x.to_i, y.to_i, speed.to_i)
end

.send(text, mode = :special) ⇒ Object



93
94
95
96
# File 'lib/autoit-ffi.rb', line 93

def send(text, mode = :special)
  mode_int = mode.to_sym == :raw ? 1 : 0
  self.AU3_Send(to_utf16(text), mode_int)
end

.shutdown(*args) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/autoit-ffi.rb', line 102

def shutdown(*args)
  if args.size == 1 && args.first.is_a?(Fixnum)
    self.AU3_Shutdown(args.first.to_i)
  else
    options_hash = {logoff: 0, shutdown: 1, reboot: 2, force: 4, power_down: 8}
    options = options_hash.keys & args.map(&:to_sym)
    opt_num = options.map { |option| options_hash[option] }.inject(:+)
    raise ArgumentError, "Illegal arguments #{args.inspect}" if opt_num.nil?
    self.AU3_Shutdown(opt_num.to_i)
  end
end

.sleep(milliseconds) ⇒ Object



98
99
100
# File 'lib/autoit-ffi.rb', line 98

def sleep(milliseconds)
  self.AU3_Sleep(milliseconds.to_i)
end

.tool_tip(tip, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT) ⇒ Object



114
115
116
# File 'lib/autoit-ffi.rb', line 114

def tool_tip(tip, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT)
  self.AU3_ToolTip(to_utf16(tip), x.to_i, y.to_i)
end

.win_close(title, text = "") ⇒ Object



118
119
120
121
# File 'lib/autoit-ffi.rb', line 118

def win_close(title, text = "")
  result = self.AU3_WinClose(to_utf16(title), to_utf16(text))
  result == 1
end

.win_exists?(title, text = "") ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
# File 'lib/autoit-ffi.rb', line 123

def win_exists?(title, text = "")
  result = self.AU3_WinExists(to_utf16(title), to_utf16(text))
  result == 1
end

.win_kill(title, text = "") ⇒ Object



128
129
130
# File 'lib/autoit-ffi.rb', line 128

def win_kill(title, text = "")
  self.AU3_WinKill(to_utf16(title), to_utf16(text))
end

.window_minimize_allObject



81
82
83
# File 'lib/autoit-ffi.rb', line 81

def window_minimize_all
  self.AU3_WinMinimizeAll
end

.window_minimize_all_undoObject



85
86
87
# File 'lib/autoit-ffi.rb', line 85

def window_minimize_all_undo
  self.AU3_WinMinimizeAllUndo
end