Reputation: 1
I want to make a simple script, with which the mouse release and press the right mouse button automatically when I hold the right mouse button. But I come across a wird problem.
Lua code:
function OnEvent(event, arg)
OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
repeat
ReleaseMouseButton(3)
OutputLogMessage("RELEASED.\n")
Sleep(300)
rbPressed = IsMouseButtonPressed(3)
PrintBool(rbPressed)
--PressMouseButton(3)
OutputLogMessage("PRESSED.\n")
until not rbPressed
end
When I comment out the PressMouseButton(3)
as above, press down the right mouse button with enough time (>300ms) and release the button, I get the following log:
Event: MOUSE_BUTTON_PRESSED Arg: 2
RELEASED.
True
PRESSED.
RELEASED.
True
PRESSED.
RELEASED.
False
PRESSED.
Event: MOUSE_BUTTON_RELEASED Arg: 2
RELEASED.
False
PRESSED.
As you can see the rbPressed
after the release is True
, it seems to be the state of pysical mouse button, not the simulated release action. However, the rbPressed
becomes False
with the PressMouseButton(3)
line. The log:
Event: MOUSE_BUTTON_PRESSED Arg: 2
RELEASED.
False
PRESSED.
Event: MOUSE_BUTTON_RELEASED Arg: 2
RELEASED.
False
PRESSED.
How could this be? since the PressMouseButton(3)
line is behind the IsMouseButtonPressed(3)
line, it shouldn't influence the FIRST output of rbPressed
.
Upvotes: 0
Views: 4297
Reputation: 23747
As you can see the rbPressed after the release is True, it seems to be the state of pysical mouse button, not the simulated release action.
IsMouseButtonPressed
returns simulated button, not physical.
ReleaseMouseButton(3)
was ignored because PressMouseButton(3)
was not called before.
There is an internal counter, PressMouseButton
increases it, ReleaseMouseButton
decreases.
When the counter = 0, ReleaseMouseButton
is ignored.
Upvotes: 0