Logitech G Hub LUA脚本根据上一个状态进行切换

刚拿到新的Logitech鼠标,我想制作一个脚本来切换状态。本质上,让鼠标按钮循环输出内容。我以前从未制作过lua脚本,所以需要一些帮助。基本上我想发生的事情的例子是:

    #设置默认状态
    state = F9;
    if (state == f9)
    when mouse4 is pressed send f10
    state = f10;

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

希望这意义清楚。如果可以用Logitech G Hub lua脚本完成,那么如果有人能向我展示脚本应该是什么样子就太好了。或者即使是Auto Hot Key,我也想象得到可以做到这一点。

编辑: 感谢Egor,好的我组装了一个版本,可以使用两个按钮。我尝试实现的是,你按下鼠标11,它会在f7或f8之间切换,具体取决于上次返回什么。我添加了另一个按钮,鼠标10,也应该在上次按下的基础上在f7和f9之间切换。但是不知何故,鼠标11的部分并没有在两者之间切换,只返回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
点赞
用户1847592
用户1847592
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
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
2020-04-13 10:55:23