0
votes

Just got a new Logitech mouse, I would like to make a script to sort of toggle between states. Essentially have a mouse button cycle through what it outputs. I have never made a lua script before so some help would be appreciated. Basically an example of what I want to happen is

    #set default state
    state = F9;
    if (state == f9)
    when mouse4 is pressed send f10
    state = f10;

    if (state == f10)
    when mouse4 is pressed send f9
    state = f9;

I hope that makes sense. If there is a way to do this with the Logitech G Hub lua scripts that would be amazing if someone could show me what the script should look like. Either that or even Auto Hot Key could probably do this I imagine.

EDIT: Thanks Egor, Okay so I put together a version that works (or should work) with two buttons. What I am trying to accomplish is you press mouse 11 and it toggles between returning either f7 or f8 depending on what it last returned. I added another button, mouse 10 that should then toggle between f7 and f9 also depending on what was last pressed. However for some reason the section for mouse 11 doesnt toggle between the two and only returns f9

local current_state_m4 = "f7"
local next_state_m4 = {f8 = "f7", f7 = "f8"}

local current_state_m5 = "f9"
local next_state_m5 = {f9 = "f7", f7 = "f9"}

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 11 then
    PressKey(current_state_m4)
    Sleep(30)
    ReleaseKey(current_state_m4)
    current_state_m4 = next_state_m4[current_state_m4]

    elseif event == "MOUSE_BUTTON_PRESSED" and arg == 10 then
    PressKey(current_state_m5)
    Sleep(30)
    ReleaseKey(current_state_m5)
    current_state_m4 = next_state_m5[current_state_m5]
  end
end

1
You have a typo.Egor Skriptunoff

1 Answers

1
votes
local current_state = "f9"
local next_state = {f10 = "f9", f9 = "f10"}

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then
      current_state = next_state[current_state]
      PressKey(current_state)
      Sleep(30)
      ReleaseKey(current_state)
   end
end