Rick
Rick

Reputation: 3

Lua script for g502

i'm trying to make a script for my mouse for a game . Basically this is what it has to do:

  1. when num lock is OFF he must press the q key every time right mouse and left mouse clicked are simultaneously
  2. When num lock is ON he must do the passage 1 but with the addition that when I hold down the right mouse button (ads) press the f key and press the f key again when the right mouse button is released

Here's the code i've been trying to write but can't figure out the 2 part of my request:

Thanks for the help :)

local zoomed = false
local weapons = true
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)

  if (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and weapons) then
    zoomed = true
  end

  if (event == "MOUSE_BUTTON_RELEASED" and arg == 2 and weapons) then
    zoomed = false
  end


    if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and zoomed) then
      PressKey("q")
      ReleaseKey("q")
      end
  if IsKeyLockOn("numlock")then    
    if (event == "MOUSE_BUTTON_PRESSED" and arg == 2) then  
      PressKey("f")
      Sleep(5)
      ReleaseKey("f")
        
   
   end
  end
end    

Upvotes: 0

Views: 2011

Answers (1)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23747

Set flag press_F_on_RMB_release to know that F should be pressed on the next right mouse button release event.

local RMB_pressed = false
local press_F_on_RMB_release = false

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 2 then
      RMB_pressed = true
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 2 then
      RMB_pressed = false
      if press_F_on_RMB_release then
         PressKey("f")
         Sleep(30)
         ReleaseKey("f")
         press_F_on_RMB_release = false
      end
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and RMB_pressed then
      PressKey("q")
      Sleep(30)
      ReleaseKey("q")
      if IsKeyLockOn("numlock") then      
         PressKey("f")
         Sleep(30)
         ReleaseKey("f")
         press_F_on_RMB_release = true
      end
   end
end   

Upvotes: 1

Related Questions