Like the title states, I'm attempting to recreate a script I made using only standard WinAPI functions such as IsMouseButtonPressed() PressMouseButton() ReleaseMouseButton() in hopes of making it work using a non-logitech mouse. The script is a simple one that detects when mb5/mb4 is pressed together with right mouse button to simulate keypresses, in this case pressing respectively the key O and P. So if mb5 is pressed together with right mb, it would press O, if mb4 is pressed together with right mb, it would press P.
Here is the script:
local mouseButton5Pressed = false
local mouseButton4Pressed = false
local rightMouseButtonPressed = false
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" then
if arg == 5 then
mouseButton5Pressed = true
elseif arg == 4 then
mouseButton4Pressed = true
elseif arg == 2 then
rightMouseButtonPressed = true
end
elseif event == "MOUSE_BUTTON_RELEASED" then
if arg == 5 then
mouseButton5Pressed = false
elseif arg == 4 then
mouseButton4Pressed = false
elseif arg == 2 then
rightMouseButtonPressed = false
end
end
if rightMouseButtonPressed and (mouseButton5Pressed or mouseButton4Pressed) then
if mouseButton5Pressed then
PressKey("o")
else
ReleaseKey("o")
end
if mouseButton4Pressed then
PressKey("p")
else
ReleaseKey("p")
end
else
ReleaseKeys()
end
end
function ReleaseKeys()
ReleaseKey("o")
ReleaseKey("p")
end
So far I've tried a few other versions of the script along these lines:
function OnEvent(event, arg)
if IsMouseButtonPressed(3) and (IsMouseButtonPressed(5) or IsMouseButtonPressed(4)) then
if IsMouseButtonPressed(5) then
PressKey("o")
else
ReleaseKey("o")
end
if IsMouseButtonPressed(4) then
PressKey("p")
else
ReleaseKey("p")
end
else
ReleaseKeys()
end
end
function ReleaseKeys()
ReleaseKey("o")
ReleaseKey("p")
end
However they all feel way less responsive, they stop working when you press the mouse buttons too quickly and fail to release the keys reliably once either mouse button is released, which isn't optimal considering what I intend to use the script for.
Also, since I mentionned how I would like to make it work using a non-logitech mice, I was also curious as to whether or not it was possible to implement (event == "PROFILE_ACTIVATED") in the script so you can invoke the OnEvent function without the logitech mouse. A bit like this script that can be used with any mouse:
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if (event == "PROFILE_ACTIVATED") then
repeat
if IsMouseButtonPressed(5) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
Sleep(15)
until not IsMouseButtonPressed(5)
end
until not (event == "PROFILE_ACTIVATED")
end
end
I know the formating is different since this a loop and it might not be feasible but I don't really know what else I could do. I'm a bit out of options here so any help would be greatly appreciated.
This script works without touching Logitech mouse.
When LGS/GHub profile is switched (when starting another application or when making another application window foreground),
OnEventfunction is starting.You must press NumLock (to exit
OnEventfunction) before every switch to another profile, otherwise LGS/GHub will crash.