Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Lua Simple filter for mouse button logitech

Tato

Coder
Hi all, I am very noob and I'd like to ask you help for a script using lua.

I have Gsuite program (Logitech) where is possible to script with LUA and I need to create a filter for the button of the mouse. I accidentally click a button and I simply want to add a filter, If I press the button for500ms send the click button, if I release the button before 500ms do nothing.

I tried with macro in Gsuite but I didn't found the solution.

Thank you in advance
 
Solution
Finally tested and with some small modification it works fine.

X is a key and not a mouse button so i used PressKey instead of PressMouseButton
I added also the press function that was missing.

Now when i press the button 4 on my mouse
- if i release before 500ms nothing happen
- if i relaese after 500ms the script press "X" key @ 500ms and release it @ release time + 25ms

This is the working code:

Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
    Sleep(500)
              if (IsMouseButtonPressed(4)) then
              PressKey("x")
            while IsMouseButtonPressed(arg) do
                Sleep(25)
               end
        ReleaseKey("x")
              end
    end
end
I'm not familiar with Lua, but did you check accessibility options in Windows control panel? Over there I think you have an accidental keypress suspender, maybe there is something similar for mouse instead keyboard.

Otherwise, I skimmed over docs you provided, you can try this:

Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
        sleep(500)
        if (IsMouseButtonPressed(arg)) then
            return false -- propagating click event
        else
            return true -- cancelling click event
        end
    end
end

You may have problems with immediate propagation of mouse click, so you may experience two clicks, one imediately, one after half a second. If that's the case, you have to find a way how to suspend the first click propagation, i.e. how to cancel it.

[Edit]
I think I found a way to access click propagation. I made changes to code.
 
Last edited:
Tried, sleep modified in Sleep uppercase (not the script gived me an error) but nothing happen.
Tried this without results:
Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
        Sleep(500)
        if (IsMouseButtonPressed(arg)) then
            return false -- propagating click event
        else
            return true -- cancelling click event
        end
    end
end

>Tried also this to see the results but without any xxx or yyy results.
I am tryng to understand how to see the result in the g-suite script editor.

Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
        Sleep(500)
        if (IsMouseButtonPressed(arg)) then
            return false -- OutputLogMesssage("yyy");
        else
            return true -- OutputLogMesssage("xxx");
        end
    end
end
 
Last edited:
Finaly i found this solution:

Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
    Sleep(500)
              if (IsMouseButtonPressed(arg)) then
       PressAndReleaseKey("x")
       end
    end
end
 
Now I want to fix a problem.
If I press the button for 0.3 seconds ok it's filtered.
If I press for 0.5 seconds ok the function press and release.
If I press for 3 seconds the script press and release @ 0.5 sec

I'd like to filter if I release before 0.5sec but also I want not to release till I release the button.
 
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
Sleep(500)
if (IsMouseButtonPressed(arg)) then
PressMouseButton("x")
::xxx::
While(IsMouseButtonPressed(x))
Do
Goto xxx
end
ReleaseMouseButton(x)
end
end
end
 
Finally tested and with some small modification it works fine.

X is a key and not a mouse button so i used PressKey instead of PressMouseButton
I added also the press function that was missing.

Now when i press the button 4 on my mouse
- if i release before 500ms nothing happen
- if i relaese after 500ms the script press "X" key @ 500ms and release it @ release time + 25ms

This is the working code:

Code:
function OnEvent(event, arg)
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
    Sleep(500)
              if (IsMouseButtonPressed(4)) then
              PressKey("x")
            while IsMouseButtonPressed(arg) do
                Sleep(25)
               end
        ReleaseKey("x")
              end
    end
end
 
Solution

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom