anyone here work with the win32 api or the autome(http://miere.ru/docs/autome) package recently?
I'm working on basic moving and clicking and seem to be failing on the click() proc
nim c -r main.nim
import autome
mouse
.move(25,840)
.click()
The click proc is defined here and I printed each step of it and it seems to work up until we get to sendInput
proc click*(m: MouseCtx, button: MouseButton, x, y: int32): MouseCtx
{.sideEffect, mouseAction, discardable.} =
## emulates mouse press and release event.
var inputs: array[2, MOUSEINPUT]
ic "inputs: " & $inputs
inputs[0] = initMouseInput(x, y, MOUSEEVENTF_ABSOLUTE or mouseButtonToDownFlags(button))
ic "inputs[0]: " & $inputs[0]
inputs[1] = initMouseInput(x, y, MOUSEEVENTF_ABSOLUTE or mouseButtonToUpFlags(button))
ic "inputs[1]: " & $inputs[1]
########## Issue Here ################
let res = sendInput(len(inputs).uint, inputs[0].addr, sizeof(MOUSEINPUT))
ic "res: " & $res
ic "len(inputs).uint: " & $len(inputs).uint
assert res == len(inputs).uint
output of click proc
inputs:
[
(kind: 0, dx: 0, dy: 0, mouseData: 0, dwFlags: 0, time: 0, dwExtraInfo: ...),
(kind: 0, dx: 0, dy: 0, mouseData: 0, dwFlags: 0, time: 0, dwExtraInfo: ...)
]
inputs[0]: (kind: 0, dx: 25, dy: 840, mouseData: 0, dwFlags: 32770, time: 0, dwExtraInfo: ...)
inputs[1]: (kind: 0, dx: 25, dy: 840, mouseData: 0, dwFlags: 32772, time: 0, dwExtraInfo: ...)
res: 0
len(inputs).uint: 2
the send input proc that is being called
proc sendInput(cInputs: uint, pInputs: pointer, cbSize: int): uint
{.importc: "SendInput".}
On reading the win32 API (https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput) it looks like the SendInput should return back 2 on successful execution
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput#return-value
The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError.
This function fails when it is blocked by UIPI. Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking.
When I execute it it's returning 0 which, if the docs are correct, looks like it's being blocked by another thread or a UIPI issue
I also tried GetLastError
ic "len(inputs).uint: " & $len(inputs).uint
if res != len(inputs).uint:
echo getLastError()
#assert res == len(inputs).uint
which yielded error code 87 (https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499-)
ERROR_INVALID_PARAMETER
87 (0x57)
but I don't think this is correct especially since the win32 docs state
This function fails when it is blocked by UIPI. Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking.
This is where i've been stumped for a few days and not sure how to proceed. Ive tried compiling the app and running it in admin mode, but still nothing
Any help would be appreciated!