Logitech Script, 1st and 2nd click events with time reset

1k Views Asked by At

What I want to do is if I press the button on my mouse it uses a key like "E" and if I press the button again it uses the key "W" and after 2 seconds it resets, I mean if I don’t press the same button after 2 seconds it uses letter "e " again. Is that possible?

I've tried some codes but no results yet:

  function OnEvent(event, arg, family)
    if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then 
    toggle = not toggle
    if toggle then
      PressKey("e")
      ReleaseKey("e") 
    else  
      PressKey("w")
      ReleaseKey("w")
    end
  end
end
1

There are 1 best solutions below

0
Egor Skriptunoff On
local prev_tm_btn5 = -math.huge

function OnEvent(event, arg, family)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
      local tm = GetRunningTime()
      local key = tm - prev_tm_btn5 > 2000 and "e" or "w"
      prev_tm_btn5 = tm
      PressKey(key)
      Sleep(15)
      ReleaseKey(key)
   end
end