首页 > 解决方案 > 罗技 G Hub LUA 脚本根据上次状态切换

问题描述

刚买了一个新的罗技鼠标,我想制作一个脚本来在状态之间切换。基本上有一个鼠标按钮循环它输出的内容。我以前从未制作过 lua 脚本,因此将不胜感激。基本上我想要发生的一个例子是

    #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;

我希望这是有道理的。如果有办法使用 Logitech G Hub lua 脚本来做到这一点,如果有人能告诉我脚本应该是什么样子,那就太棒了。我想,那个甚至自动热键都可能做到这一点。

编辑:谢谢 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

标签: luaautohotkeylogitechlogitech-gaming-software

解决方案


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

推荐阅读