-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrobotgo.lua
More file actions
258 lines (218 loc) · 5.1 KB
/
robotgo.lua
File metadata and controls
258 lines (218 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
-- // Copyright (c) 2019-2025 AtomAI, All rights reserved.
--
-- // This is a commercial product and requires a license to operate.
-- // A trial license can be obtained at https://atomai.cc/user/singup
-- //
-- // DO NOT EDIT: generated by tools
-- // Use of this source code is governed by the AtomAI End User License Agreement
-- // terms that can be accessed at https://atomai.cc/about/eula/
local ffi = require("ffi")
local is_64bit = ffi.abi("64bit")
if is_64bit then
ffi.cdef[[
typedef long GoInt;
]]
else
ffi.cdef[[
typedef int GoInt;
]]
end
ffi.cdef[[
typedef struct {
GoInt x;
GoInt y;
} GoRInt;
typedef struct {
char* arr;
char* err;
} GoStr;
void Sleep1(GoInt tm);
void MilliSleep(GoInt tm);
char* GetPixelColor(GoInt x, GoInt y);
char* GetLocationColor();
GoRInt GetScreenSize();
GoRInt GetScaleSize();
void Move(GoInt x, GoInt y);
void DragSmooth(GoInt x, GoInt y);
void MoveSmooth(GoInt x, GoInt y, double low, double high);
GoRInt Location();
void Click(char* btn, bool double_c);
void Toggle(char* key, char* btn);
void Scroll(GoInt x, GoInt y);
char* KeyTap(char* key, char* vals);
char* KeyToggle(char* key, char* vals);
void Type(char* str, GoInt args);
GoStr ReadAll();
char* WriteAll(char* str);
void Paste(char* str);
bool Alert(char* title, char* msg);
char* GetTitle(GoInt pid);
GoStr FindIds(char* name);
GoStr FindName(GoInt pid);
GoStr FindNames();
char* ActivePid(GoInt pid);
char* ActiveName(char* name);
char* Kill(GoInt pid);
]]
local function gs()
local str = debug.getinfo(2, "S").source:sub(2)
local dir = str:match("(.*[/\\])")
return dir or "./"
end
local lib_path
local arch = ffi.arch
if ffi.os == "OSX" then
lib_path = "robotgo.dylib"
if arch == "x64" or arch == "x86" then
lib_path = "robotgo_x86.dylib"
end
elseif ffi.os == "Windows" then
lib_path = "robotgo_x86.dll"
if arch == "arm64" or arch == "arm64be" then
lib_path = "robotgo.dll"
end
else
lib_path = "robotgo_x86.so"
if arch == "arm64" or arch == "arm64be" then
lib_path = "robotgo.so"
end
end
local script_dir = gs()
local lib_path1 = script_dir .. lib_path
local lib = ffi.load(lib_path1)
local function ts(cstr)
if cstr == nil then
return nil
end
return ffi.string(cstr)
end
local function ch(str)
return ffi.cast("char*", str)
end
--
local robotgo = {}
function robotgo.GetVersion()
return ""
end
function robotgo.Sleep(tm)
lib.Sleep1(tm)
end
function robotgo.MilliSleep(tm)
lib.MilliSleep(tm)
end
--
function robotgo.GetPixelColor(x, y)
local color = lib.GetPixelColor(x, y)
return ts(color)
end
function robotgo.GetLocationColor()
local color = lib.GetLocationColor()
return ts(color)
end
function robotgo.GetScreenSize()
local s = lib.GetScreenSize()
return s.x, s.y
end
function robotgo.GetScaleSize()
local s = lib.GetScaleSize()
return s.x, s.y
end
--
function robotgo.Move(x, y)
lib.Move(x, y)
end
function robotgo.DragSmooth(x, y)
lib.DragSmooth(x, y)
end
function robotgo.MoveSmooth(x, y, low, high)
low = low or 1.0
high = high or 3.0
lib.MoveSmooth(x, y, low, high)
end
function robotgo.Location()
local s = lib.Location()
return s.x, s.y
end
function robotgo.Click(btn, double_c)
btn = btn or "left"
double_c = double_c or false
lib.Click(ch(btn), double_c)
end
function robotgo.Toggle(key, btn)
lib.Toggle(ch(key), ch(btn))
end
function robotgo.Scroll(x, y)
lib.Scroll(x, y)
end
--
local function aa(...)
local args = {...}
if #args == 0 then
return ""
end
return table.concat(args, ",")
end
function robotgo.KeyTap(key, ...)
local a = aa(...)
local s = lib.KeyTap(ch(key), a)
return ts(s)
end
function robotgo.KeyToggle(key, ...)
local a = aa(...)
local s = lib.KeyToggle(ch(key), a)
return ts(s)
end
function robotgo.Type(str, args)
args = args or 0
lib.Type(ch(str), args)
end
local function e1(s)
local e = ts(s.err)
if e == nil or e == "" then
return ts(s.arr)
end
return ""
end
function robotgo.ReadAll()
local s = lib.ReadAll()
return e1(s)
end
function robotgo.WriteAll(str)
return lib.WriteAll(ch(str))
end
function robotgo.Paste(str)
lib.Paste(ch(str))
end
--
function robotgo.Alert(title, msg)
return lib.Alert(ch(title), ch(msg))
end
function robotgo.GetTitle(pid)
local title = lib.GetTitle(pid)
return ts(title)
end
function robotgo.FindIds(name)
local s = lib.FindIds(ch(name))
return e1(s)
end
function robotgo.FindName(pid)
local s = lib.FindName(pid)
return e1(s)
end
function robotgo.FindNames()
local s = lib.FindNames()
return e1(s)
end
function robotgo.ActivePid(pid)
local result = lib.ActivePid(pid)
return ts(result)
end
function robotgo.ActiveName(name)
local result = lib.ActiveName(ch(name))
return ts(result)
end
function robotgo.Kill(pid)
local result = lib.Kill(pid)
return ts(result)
end
return robotgo