-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
32 lines (26 loc) · 887 Bytes
/
main.lua
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
local ffi = require("ffi")
require("win32.sdkddkver")
require("win32.errhandlingapi")
require("win32.wingdi")
require("win32.winuser")
require("win32.winerror")
local C = ffi.C
local user32 = ffi.load"user32"
ffi.cdef("size_t strlen(const char *);")
function SendValve001Command(msg)
local Valve001 = user32.FindWindowA("Valve001", nil)
local Valve001Num = tonumber(ffi.cast("intptr_t", Valve001))
if Valve001Num == 0 then return nil, 'Valve001 not found' end
local copyData = ffi.new("COPYDATASTRUCT[1]", {
{
dwData = 0x0,
cbData = C.strlen(msg) + 1,
lpData = ffi.cast("void*", msg)
}
})
local ok = user32.SendMessageA(Valve001, C.WM_COPYDATA, ffi.cast("WPARAM", Valve001), ffi.cast("LPARAM", ffi.cast("LPVOID", copyData)))
if ok == 1 then return true end
return nil, ok == 0 and "sendmessage failed" or ok
end
local cmd = ...
return SendValve001Command(cmd)