Skip to content

Commit f4f34c6

Browse files
authored
Create main.lua
1 parent d84610e commit f4f34c6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

main.lua

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local ffi = require("ffi")
2+
require("win32.sdkddkver")
3+
require("win32.errhandlingapi")
4+
require("win32.wingdi")
5+
require("win32.winuser")
6+
require("win32.winerror")
7+
local C = ffi.C
8+
local user32 = ffi.load"user32"
9+
ffi.cdef("size_t strlen(const char *);")
10+
11+
function SendValve001Command(msg)
12+
local Valve001 = user32.FindWindowA("Valve001", nil)
13+
local Valve001Num = tonumber(ffi.cast("intptr_t", Valve001))
14+
if Valve001Num == 0 then return nil, 'Valve001 not found' end
15+
16+
local copyData = ffi.new("COPYDATASTRUCT[1]", {
17+
{
18+
dwData = 0x0,
19+
cbData = C.strlen(msg) + 1,
20+
lpData = ffi.cast("void*", msg)
21+
}
22+
})
23+
24+
local ok = user32.SendMessageA(Valve001, C.WM_COPYDATA, ffi.cast("WPARAM", Valve001), ffi.cast("LPARAM", ffi.cast("LPVOID", copyData)))
25+
if ok == 1 then return true end
26+
27+
return nil, ok == 0 and "sendmessage failed" or ok
28+
end
29+
30+
print("SendValve001Command", SendValve001Command("say asd"))

0 commit comments

Comments
 (0)