module AutoItFFI::AutoIt
Constants
- AU3_INTDEFAULT
“Default” value for some int parameters (largest negative number)
- UTF_16LE_NULL
Used when constructing strings consumed by
AutoIt
Public Instance Methods
admin?()
click to toggle source
# File lib/autoit-ffi.rb, line 32 def admin? self.AU3_IsAdmin == 1 end
auto_it_set_option(option, value)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_get()
click to toggle source
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.
# 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)
click to toggle source
# 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
error()
click to toggle source
# File lib/autoit-ffi.rb, line 24 def error self.AU3_error end
get_mouse_pos_x()
click to toggle source
# File lib/autoit-ffi.rb, line 73 def get_mouse_pos_x self.AU3_MouseGetPosX end
get_mouse_pos_y()
click to toggle source
# File lib/autoit-ffi.rb, line 77 def get_mouse_pos_y self.AU3_MouseGetPosY end
mouse_wheel(direction, clicks)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/autoit-ffi.rb, line 98 def sleep(milliseconds) self.AU3_Sleep(milliseconds.to_i) end
to_utf16(object)
click to toggle source
All AutoIt
functions that take strings expect the strings to be of the “LPCWSTR” or “LPWSTR” types, which use 2 bytes per character. This method calls to_s on its argument and converts the string to UTF-16LE so that AutoIt
can use it. Note that the NULL character must be explicitly added.
# File lib/autoit-ffi.rb, line 139 def to_utf16(object) object.to_s.encode("UTF-16LE") + UTF_16LE_NULL end
tool_tip(tip, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT)
click to toggle source
# 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 = "")
click to toggle source
# 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 = "")
click to toggle source
# 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 = "")
click to toggle source
# File lib/autoit-ffi.rb, line 128 def win_kill(title, text = "") self.AU3_WinKill(to_utf16(title), to_utf16(text)) end
window_minimize_all()
click to toggle source
# File lib/autoit-ffi.rb, line 81 def window_minimize_all self.AU3_WinMinimizeAll end
window_minimize_all_undo()
click to toggle source
# File lib/autoit-ffi.rb, line 85 def window_minimize_all_undo self.AU3_WinMinimizeAllUndo end