I need Lua script start when I press M4 button on mouse press keys but I need this in loop until I press M4 again.
-- NOT HOLD - PRESS AGAIN --
here is my code;
local M4_pressed = false
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then
M4_pressed = not M4_pressed
while M4_pressed do
PressKey("2")
Sleep(math.random(60, 70))
ReleaseKey("2")
Sleep(math.random(60, 70))
end
end
end
this is my code but its not stopping on press again.
M4_pressed = not M4_pressed
/*this means
if(M4_pressed = true){M4_pressed = false)}
if(M4_pressed = false){M4_pressed = true)}
*/
You should write a function to poll the MB4 status while sleeping.
Transition of
IsMouseButtonPressed(4)fromfalsetotruemeans MB4 is pressed for the second time.