简体   繁体   中英

Assigning Lua Script to a Button - Logitech G500s

I have a small macro for my Logitech G500s - i'm using it in FPS games to reduce recoil. Please see script below:

EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 1  then
        repeat
            MoveMouseRelative(-1,2)
            Sleep(16)
        until not IsMouseButtonPressed(1)
    end
end

Problem is that this script is works constantly. I wish rather to push another button1 to start using script on button2 and re-press button1 to break script

I was trying to set up the flags such as:

unction OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then --set flag for mb1
                mb1_pressed = true
        elseif event == "MOUSE_BUTTON_RELEASED" and arg == 6 then --set flag for mb1=false
        mb1_pressed = false
        end 

If mb1_pressed then
    if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and  then
        repeat
            MoveMouseRelative(-1,2)
            Sleep(16)
        until not IsMouseButtonPressed(1)
    end

end  

but it does not work. Could you please help me ?

 if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then --set flag for mb1
            mb1_pressed = true
 elseif event == "MOUSE_BUTTON_RELEASED" and arg == 6 then --set flag for mb1=false
    mb1_pressed = false
 end

This will set mb1_pressed when mouse button is pressed and unset it when it is released. So, the variable will only be true while the button is pressed.

If you want to toggle the mb1_pressed value on each press, you can do something like

if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then --toggle flag for mb1
            mb1_pressed = not mb1_pressed
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM