I'm not familiar with Lua, just writing some lua script for logitech mouse to play game.....
Here is what I expected: when I press some key on mouse, it began to press '1' on the keyboard, and when I press the mouse key again, it just stop.
And here is what I've tried: I use a global flag to keep track of the switch, but it won't stop once begin....I don't know how lua handle events, and I suppose global flag is not a good idea. So any better way to do this?
here is the code:
on = 0
cd = 50
function shift_example()
while on do
PressAndReleaseKey("1")
Sleep(cd)
end
end
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %s\n", event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and on ==0) then
OutputLogMessage("set on = true\n")
on = 1
shift_example()
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and on == 1) then
OutputLogMessage("set on = false\n")
on = 0
end
end