Logitech Script Binding - lua

I just made a script which has some mouse movement and presskey action. I am trying to bind F6 button instead of mouse button 5. How can I bind F6 button in this script? Namely, it is going to be like "if "F6" pressed then ...
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
MoveMouseTo(60000, 11000)
PressAndReleaseMouseButton(1)
Sleep(20)
PressAndReleaseKey("y")
end
end

Related

How to stop a repeated list of actions when releasing LMB

I have a list of actions as follows:
PressAndReleaseKey("f13") -- Action 1
Sleep(200)
PressAndReleaseKey("f13") -- Action 2
Sleep(200)
PressKey("f13") -- Action 3
Sleep(400)
ReleaseKey("f13") -- Action 4
Sleep(200)
I want to repeat these actions when pressing LMB and cancel all actions whenever release LMB
Eg:
if LMB is pressed for 300 ms and then released => only Action 1 and Action 2 will be executed (1 time),
if LMB is pressed for 1800 ms and then released => Action 1 and 2 will be executed twice, Action 3 will be executed once.
So pls help me, this is my script so far:
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
if IsMouseButtonPressed(1) then
repeat
PressAndReleaseKey("f13") -- Action 1
Sleep(200)
PressAndReleaseKey("f13") -- Action 2
Sleep(200)
PressKey("f13") -- Action 3
Sleep(400)
ReleaseKey("f13") -- Action 4
Sleep(200)
until not IsMouseButtonPressed(1)
end
end
end
(Option 2) In case such repeat is not possible => there is another more manual option like local that list actions up to 100 times
You cannot cancel any action. You can either execute it or not. Once it is triggered you cannot stop it.
If you want to stop execution after Action 1 and Action 2 you have to check the button state after Action 2 and only execute Action 3 if the button is still pressed. Currently you're checking the button only after all actions have been executed.
Place if not IsMouseButtonPressed(1) then break end befor any action so it will not be executed if the button is pressed.

Hi how to use the lua script in order to toggle macro on and off

function OnEvent(event, arg, family)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and family == "mouse") then
PlayMacro("Lustre Rotation")
end
if (event == "MOUSE_BUTTON_RELEASED" and arg == 5 and family == "mouse") then
AbortMacro()
end
end
Hi I've been using the lua script (on Logitech G Hub) above in order to stop the macro as soon as I release the mouse button, but I don't wanna hold mouse button, instead I want to use the mouse button to toggle the macro. Please guide me through the script how to change to toggle on/off macro with mouse button. Thank you!
function OnEvent(event, arg)
if event == "G_PRESSED" and arg == 1 then
AutoToggle = not AutoToggle
if AutoToggle then
PlayMacro("Lustre Rotation")
else
AbortMacro()
end
end

Script for pressing a keyboard key when a mouse button is pressed

I'm trying to give me logitech mouse an order using lua script that when the primary key is pressed a key in the keyboard is also clicked until I stop holding the mouse button
I tried this one but it works perfectly with all the mouse buttons but no actions happens when I set it up for the primary key.
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
PressKey("V")
end
if event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
ReleaseKey("V")
end
end
any help?
Thanks in Advance.
By default primary mouse button events are disabled.
You need to enable them explicitly.
local v_pressed
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("scrolllock") then
PressKey("V")
v_pressed = true
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 and v_pressed then
ReleaseKey("V")
end
end
UPDATE
The script works only when ScrollLock LED is on.

Logitech/LGHUB Lua - Loop with break

i recently picked up Lua while making a macro script for my LG mouse.
Unfortunately the Lua-API is really restricted with debug, io and file not working (source: http://www.softpanorama.org/Hardware/Peripherals/Keyboards/Logitech_G_keyboard_macros/lua_scripting.shtml#Limitations)
Here is also the official reference: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
The script is running a LGHUB macro while i want to attach mouse movement to that macro while it is running. There is no function for checking if a macro is currently running to just loop and stop the lua-side.
So I'm looking for a possibility in Lua to 'run a loop independent' which does not stop the execution of the rest of my script (to check if a status variable [isMacroRunning] has changed). I also want to break that macro if i hit another button while the macro is running.
BUT if i loop the mouse-movement, i cannot trigger another onEvent-function because the script-pointer(?) is still stuck in my loop. My current idea is to break that with a coroutine but iam not sure how to continue while no key-input is happening.
The script doesnt stop and wait if it encounters 'PlayMacro()', also this API-Function has no return value to just attach lua actions to the PlayMacro-function.
There would be also the possibility to transfer the LGHUB-macro (essentially its just pressButton A and leftclick for 40s then release the buttons) but that doesnt solve the problem (at least i cant find a solution within this) with the function being stuck in the loop and no way to break it.
For example, if MouseButton11 triggers a loop and i press MouseButton10, the $arg variable does not change to 10 but stays at 11 because the script-pointer(?) is still in the loop instead of triggering the onEvent function.
The script seems to get executed once at load (example on switching mouse-profiles) and then the onEvent-function listens. If i could somehow run a looping check on [isMacroRunning] while still be able to trigger the onEvent-function, i can make this work. But otherwise i know to little about Lua and its behavior.
Edit1: Added "essential script" which only describes the needed core-functions. This is not working due to a 2nd onEvent cannot be triggered until the 1st onEvent has finished. But the 1st onEvent is designed to break on a variable change. The variable change is triggered in the 2nd onEvent. Needed solution: some kind of workaround or use of other Lua functions to seperate the 1st onEvent execution from the 2nd onEvent.
Essential Script:
```
isMacroRunning = false
function wiggle()
PressKey("a")
while true do
if not isMacroRunning then break end
OutputLogMessage("wiggle\n")
MoveMouseRelative (5, 0)
Sleep(150)
MoveMouseRelative (-5, 0)
Sleep(150)
end
end
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 11) then
isMacroRunning = true
wiggle()
end
if(event == "MOUSE_BUTTON_PRESSED" and arg == 10 and isMacroRunning) then
isMacroRunning = false
ReleaseKey("a")
end
end
´´´
Full Script:
local isMacroRunning = false
coco = coroutine.create(function()
while true do
if not isMacroRunning then break end
MoveMouseRelative (5, 0)
Sleep(150)
MoveMouseRelative (-5, 0)
Sleep(150)
coroutine.yield()
end
end)
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 11) then
isMacroRunning = true
runMacro()
elseif(event == "MOUSE_BUTTON_PRESSED" and arg == 10 and isMacroRunning) then
isMacroRunning = false
runMacro()
end
end
function runMacro()
if isMacroRunning then
PlayMacro('farm')
coroutine.resume(coco)
OutputLogMessage("Start Macro\n")
else
AbortMacro()
OutputLogMessage("Aborted\n")
end
end
coroutine.resume(coco)
´´´
Step 1.
Make sure you're not using MB#4 ("backward") in the game.
If some action is assigned to MB#4 in the game, do the following:
choose keyboard button you don't currently use in the game (for example, F12)
goto GHUB(KEYS tab); bind F12 to your physical MB#4
goto game options; bind the action to F12 instead of MB#4
Now when you press physical MB#4, the game sees F12 and executes your old action.
Step 2.
Goto GHUB(SYSTEM tab); bind "Back" to MB#10
Step 3.
The script.
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 11 then
PressMouseButton(1) -- down LMB
PressKey("A") -- down "A"
repeat
MoveMouseRelative(5,0)
Sleep(150)
MoveMouseRelative(-5,0)
Sleep(150)
until IsMouseButtonPressed(4) -- btn#4 is bound to btn#10
ReleaseKey("A") -- up "A"
ReleaseMouseButton(1) -- up LMB
end
end
How does it work:
When you press MB#11, the loop starts.
When you later press MB#10, IsMouseButtonPressed() sees that button#4 is pressed, and the loop exits.

Lua Scripting error with G-Key script SetMkeyState

I have a G602 mouse and I want to use the DPI sensitive buttons (G10, G11) to control the M-Key state of my G910 keyboard. I'm trying to write a Lua script for it, but I'm having problems trying to set the M-Key state based off the API documentation sample:
if event == "MOUSE_BUTTON_PRESSED" and arg == 11 then
SetMkeyState(1,"kb")
end
I get the following error:
[string "LuaVM"]:20: attempt to call global 'SetMkeyState' (a nil value)
I even tried the exact sample from the API documentation and I get the same error:
-- Set the current M Key state to M1 when G1 is pressed
function OnEvent(event, arg)
if (event == "G_PRESSED" and arg == 1) then
SetMkeyState(1);
end
end
The command is case-sensitive and the sample in API Documentation has a typo. The letter K in SetMkeyState should be upper-case.
Using SetMKeyState works:
if event == "MOUSE_BUTTON_PRESSED" and arg == 11 then
SetMKeyState(1,"kb")
end

Resources