autoit-ffi 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/dll/AutoItX3.dll +0 -0
- data/lib/autoit-ffi.rb +145 -0
- data/lib/function_attacher.rb +46 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3613690a78037261fc15a2a6723f52c469b87694
|
4
|
+
data.tar.gz: 18ea7e0989be9142041bfd6f689e94e465df4076
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f392109bdfb476f33e133a061c18dd46786088c56120931880da6f499e53625d7f59997ff778f17e95b59fc3d6206b7b8307d1373dd0f20377ce0d7a483e5a11
|
7
|
+
data.tar.gz: d80020b667b23952752531214b71c1e9545365a6c6762b8ecb17f20872fb7e6f378d382dc30347c23212c9bc8927feccfb62c4073441a3c927203155b9624e3d
|
data/dll/AutoItX3.dll
ADDED
Binary file
|
data/lib/autoit-ffi.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
require 'ffi'
|
4
|
+
require_relative 'function_attacher'
|
5
|
+
|
6
|
+
module AutoItFFI
|
7
|
+
|
8
|
+
module AutoIt
|
9
|
+
|
10
|
+
# "Default" value for _some_ int parameters (largest negative number)
|
11
|
+
AU3_INTDEFAULT = -2147483647
|
12
|
+
# Used when constructing strings consumed by AutoIt
|
13
|
+
UTF_16LE_NULL = "\0".encode("UTF-16LE")
|
14
|
+
|
15
|
+
extend FFI::Library
|
16
|
+
ffi_lib File.expand_path(File.dirname(__FILE__)) + "/../dll/AutoItX3.dll"
|
17
|
+
ffi_convention :stdcall
|
18
|
+
|
19
|
+
FunctionAttacher.attach(self)
|
20
|
+
self.AU3_Init
|
21
|
+
|
22
|
+
module_function
|
23
|
+
|
24
|
+
def error
|
25
|
+
self.AU3_error
|
26
|
+
end
|
27
|
+
|
28
|
+
def auto_it_set_option(option, value)
|
29
|
+
self.AU3_AutoItSetOption(to_utf16(option), value.to_i)
|
30
|
+
end
|
31
|
+
|
32
|
+
def admin?
|
33
|
+
self.AU3_IsAdmin == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def block_input(flag)
|
37
|
+
flag_int = flag ? 1 : 0
|
38
|
+
self.AU3_BlockInput(flag_int)
|
39
|
+
end
|
40
|
+
|
41
|
+
def cd_tray(drive, action)
|
42
|
+
result = self.AU3_CDTray(to_utf16(drive), to_utf16(action))
|
43
|
+
result == 1
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# TODO: currently this method allocates a buffer that can hold 10000 utf16 characters to which
|
48
|
+
# the clipboard data is read to. A better approach would be to first query the size of the clipboard
|
49
|
+
# and allocate a buffer that fits that size. Note that the program will crash if there is more than 10000
|
50
|
+
# characters in the clipboard.
|
51
|
+
#
|
52
|
+
def clip_get
|
53
|
+
buffer = FFI::MemoryPointer.new(:uint16, 10000, true) # allocate 20000 bytes and zero out the memory.
|
54
|
+
self.AU3_ClipGet(buffer, 10000)
|
55
|
+
clipboard_data = buffer.read_string(buffer.size)
|
56
|
+
clipboard_data.force_encoding("UTF-16LE").encode("UTF-8").rstrip
|
57
|
+
end
|
58
|
+
|
59
|
+
def control_click(title, text, control, button, num_clicks, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT)
|
60
|
+
self.AU3_ControlClick(to_utf16(title),
|
61
|
+
to_utf16(text),
|
62
|
+
to_utf16(control),
|
63
|
+
to_utf16(button),
|
64
|
+
num_clicks.to_i,
|
65
|
+
x.to_i,
|
66
|
+
y.to_i)
|
67
|
+
end
|
68
|
+
|
69
|
+
def move_mouse(x, y, speed = 10)
|
70
|
+
self.AU3_MouseMove(x.to_i, y.to_i, speed.to_i)
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_mouse_pos_x
|
74
|
+
self.AU3_MouseGetPosX
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_mouse_pos_y
|
78
|
+
self.AU3_MouseGetPosY
|
79
|
+
end
|
80
|
+
|
81
|
+
def window_minimize_all
|
82
|
+
self.AU3_WinMinimizeAll
|
83
|
+
end
|
84
|
+
|
85
|
+
def window_minimize_all_undo
|
86
|
+
self.AU3_WinMinimizeAllUndo
|
87
|
+
end
|
88
|
+
|
89
|
+
def mouse_wheel(direction, clicks)
|
90
|
+
self.AU3_MouseWheel(to_utf16(direction), clicks.to_i)
|
91
|
+
end
|
92
|
+
|
93
|
+
def send(text, mode = :special)
|
94
|
+
mode_int = mode.to_sym == :raw ? 1 : 0
|
95
|
+
self.AU3_Send(to_utf16(text), mode_int)
|
96
|
+
end
|
97
|
+
|
98
|
+
def sleep(milliseconds)
|
99
|
+
self.AU3_Sleep(milliseconds.to_i)
|
100
|
+
end
|
101
|
+
|
102
|
+
def shutdown(*args)
|
103
|
+
if args.size == 1 && args.first.is_a?(Fixnum)
|
104
|
+
self.AU3_Shutdown(args.first.to_i)
|
105
|
+
else
|
106
|
+
options_hash = {logoff: 0, shutdown: 1, reboot: 2, force: 4, power_down: 8}
|
107
|
+
options = options_hash.keys & args.map(&:to_sym)
|
108
|
+
opt_num = options.map { |option| options_hash[option] }.inject(:+)
|
109
|
+
raise ArgumentError, "Illegal arguments #{args.inspect}" if opt_num.nil?
|
110
|
+
self.AU3_Shutdown(opt_num.to_i)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def tool_tip(tip, x = AU3_INTDEFAULT, y = AU3_INTDEFAULT)
|
115
|
+
self.AU3_ToolTip(to_utf16(tip), x.to_i, y.to_i)
|
116
|
+
end
|
117
|
+
|
118
|
+
def win_close(title, text = "")
|
119
|
+
result = self.AU3_WinClose(to_utf16(title), to_utf16(text))
|
120
|
+
result == 1
|
121
|
+
end
|
122
|
+
|
123
|
+
def win_exists?(title, text = "")
|
124
|
+
result = self.AU3_WinExists(to_utf16(title), to_utf16(text))
|
125
|
+
result == 1
|
126
|
+
end
|
127
|
+
|
128
|
+
def win_kill(title, text = "")
|
129
|
+
self.AU3_WinKill(to_utf16(title), to_utf16(text))
|
130
|
+
end
|
131
|
+
|
132
|
+
# --- Helpers ----
|
133
|
+
|
134
|
+
# All AutoIt functions that take strings expect the strings to be of the "LPCWSTR"
|
135
|
+
# or "LPWSTR" types, which use 2 bytes per character. This method calls to_s on its
|
136
|
+
# argument and converts the string to UTF-16LE so that AutoIt can use it. Note that the
|
137
|
+
# NULL character must be explicitly added.
|
138
|
+
#
|
139
|
+
def to_utf16(object)
|
140
|
+
object.to_s.encode("UTF-16LE") + UTF_16LE_NULL
|
141
|
+
end
|
142
|
+
private_class_method :to_utf16
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
module AutoItFFI
|
4
|
+
|
5
|
+
module FunctionAttacher
|
6
|
+
|
7
|
+
FUNCTION_PROTOTYPES = [
|
8
|
+
[ :AU3_error, [], :long ],
|
9
|
+
[ :AU3_AutoItSetOption, [:pointer, :long], :long ],
|
10
|
+
[ :AU3_ClipGet, [:pointer, :long], :void ],
|
11
|
+
[ :AU3_Init, [], :void ],
|
12
|
+
[ :AU3_BlockInput, [:long], :void ],
|
13
|
+
[ :AU3_MouseGetPosX, [], :int ],
|
14
|
+
[ :AU3_MouseGetPosY, [], :int ],
|
15
|
+
[ :AU3_IsAdmin, [], :int ],
|
16
|
+
[ :AU3_MouseMove, [:long, :long, :long], :long ],
|
17
|
+
[ :AU3_WinMinimizeAll, [], :void ],
|
18
|
+
[ :AU3_WinMinimizeAllUndo, [], :void ],
|
19
|
+
[ :AU3_MouseWheel, [:pointer, :long], :void ],
|
20
|
+
[ :AU3_CDTray, [:pointer, :pointer], :long ],
|
21
|
+
[ :AU3_Send, [:pointer, :long], :void ],
|
22
|
+
[ :AU3_Sleep, [:long], :void ],
|
23
|
+
[ :AU3_Shutdown, [:long], :long ],
|
24
|
+
[ :AU3_ToolTip, [:pointer, :long, :long], :void ],
|
25
|
+
[ :AU3_WinClose, [:pointer, :pointer], :long ],
|
26
|
+
[ :AU3_WinExists, [:pointer, :pointer], :long ],
|
27
|
+
[ :AU3_WinKill, [:pointer, :pointer], :long ]
|
28
|
+
]
|
29
|
+
|
30
|
+
|
31
|
+
# Attaches the AutoIt DLL functions to lib (which must extend FFI::Library).
|
32
|
+
# See "doc/Function Prototypes (C).txt" for the C header file.
|
33
|
+
#
|
34
|
+
def self.attach(lib)
|
35
|
+
FUNCTION_PROTOTYPES.each { |fun| lib.attach_function *fun }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# AU3_API void WINAPI AU3_MouseWheel(LPCWSTR szDirection, long nClicks);
|
42
|
+
# AU3_API long WINAPI AU3_CDTray(LPCWSTR szDrive, LPCWSTR szAction);
|
43
|
+
|
44
|
+
#AU3_API long WINAPI AU3_WinKill(LPCWSTR szTitle, /*[in,defaultvalue("")]*/LPCWSTR szText);
|
45
|
+
#AU3_API long WINAPI AU3_Shutdown(long nFlags);
|
46
|
+
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autoit-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kalle Lindström
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: FFI bindings for AutoIt
|
14
|
+
email: lindstrom.kalle@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/autoit-ffi.rb
|
20
|
+
- lib/function_attacher.rb
|
21
|
+
- dll/AutoItX3.dll
|
22
|
+
homepage: http://github.com/kl/autoit-ffi
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: FFI bindings for AutoIt
|
45
|
+
test_files: []
|