Just for the sake of clarity, here's a short script that just clicks fast as long as the 2 requirements are met (is numlock on and is mouse button 5 pressed).
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("numlock")then
repeat
if IsMouseButtonPressed(5) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
Sleep(15)
until not IsMouseButtonPressed(5)
end
until not IsKeyLockOn("numlock")
end
end
Given that numlock is toggled on, as long as you press mouse button 5 on the logitech mouse before attempting it on a non-logitech mouse, you can get the script to work on any mice. (You can also just toggle numlock on using a custom binding directly on the logitech mouse to skip that step)
Since this was the first script I ever used, it caused me to be under the impression that any mouse inputs (regardless of the brand of the mouse) could be detected in a ghub lua script. I now know that is wrong.
I then tried using a similar script, the only difference being the removal of the 'IsKeyLockOn' function and unsurprisingly, I couldn't get this one to work on a non-logitech mouse.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsMouseButtonPressed(5) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
Sleep(15)
until not IsMouseButtonPressed(5)
end
end
Could someone please explain to me why that is ? I apologize as I know this might not be as much of a coding question as it is just a logitech api question but I honestly have no clue as to what could explain this. As you've probably noticed by now, I'm basically as new as it gets when it comes to coding and the logitech lua api so any help would be greatly appreciated.
All the Logitech API functions you are using in the Lua script are actually standard WinAPI functions to work with mouse and keyboard.
IsKeyLockOn()
IsMouseButtonPressed()
PressMouseButton()
ReleaseMouseButton()
Sleep()
For example, if you press button 5 on any mouse, Windows will set its internal flag "mouse_button_5_down" to "true" (or something like that), and any software can then invoke some WinAPI function like IsMouseButtonPressed(5)
to determine if button 5 is currently down or up.
The only thing you need a Logitech mouse/keyboard for is to generate an event processed by OnEvent
- this function is invoked by Logitech driver when a Logitech device (recognized by the driver) has changed its state.
So, while you are inside OnEvent
function, you can stop using Logitech mouse and work with non-Logitech mouse.
BTW, you can avoid touching Logitech mouse at all: when a LGS/GHUB profile changed (you switched input focus to another application), the function OnEvent
is invoked with event=="PROFILE_ACTIVATED"
, and your script starts running!