lua - 罗技 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
解决方案
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
推荐阅读
- javascript - JavaScript 模板文字插值 rgba() 值
- r - 添加一个交互式按钮来切换映射哪个变量以填充 ggplotly in r
- python - 使用变量创建 @get() 请求 - bottle.py
- javascript - 使用Vue组件渲染功能时的无限循环
- scrollview - 如何在 react-native 中获取功能组件中的 ref x、y 位置?
- swift - SwiftUI 自定义视图包装器
- javascript - JavaScript - 以对象值为目标以创建另一个变量
- awk - qsub 无法识别 awk 字段变量
- php - phpdotenv 不与我一起工作并显示空白页
- react-native - React Native - TouchableOpacity 按钮的颜色应该在没有地图的情况下改变