0
votes

I have a logitech g102 mouse and i want to create a lua script which will press a different key every time i press the mouse button 4. Specifically i want each time i click the mouse button 4 to loop around 3 keyboard strokes (5,6,7). So if i click the first time my mouse button 4 it will press the number 3, the second time the number 4, third time number 5 and then repeat this as many times i press mouse button 4. I have already tried some code but didnt get anywhere. Can somebody help me?

1
Welcome to SO. In order to get this answered you are going to have to provide more information. Please have a look here at this link on how to ask a good question: stackoverflow.com/help/how-to-ask When you say you tried some code - please add that code to the question so we can see what you have tried. - Mhluzi Bhaka
this is not a coding service. please post some code where you try to solve this. the manual should actually answer all your questions - Piglet

1 Answers

0
votes
local keys = {"h", "e", "l", "l", "o"}   -- cycle of keys
local idx
local tm = -math.huge

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 4 then
      if GetRunningTime() - tm > 2000 then
         idx = 0
      end
      idx = idx % #keys + 1
      PressKey(keys[idx])
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 4 then
      ReleaseKey(keys[idx])
      tm = GetRunningTime()
   end
end