LUA scripting no recoil - lua

I have this code and I want the repeat loop to get activated after the Right click is pressed for more than .1 seconds otherwise not to get activated OR the loop to stop entirely once I release the Right click after .1 seconds both will work I suppose. Any ideas?
function OnEvent(event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
end
if IsKeyLockOn("capslock")then
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
if IsMouseButtonPressed(3) then
Sleep(30)
repeat
MoveMouseRelative(-9, 12)
Sleep(5)
MoveMouseRelative(9, -9)
Sleep(5)
until not IsMouseButtonPressed(1)
end
end
end
end

I want the repeat loop to get activated after the Right click is pressed for more than .1 seconds otherwise not to get activated
You can use the following code to accomplish this goal:
local RMB_tm = math.huge
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 2 then
RMB_tm = GetRunningTime()
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 2 then
RMB_tm = math.huge
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1
and GetRunningTime() - RMB_tm > 100 and IsKeyLockOn("capslock")
then
Sleep(30)
repeat
MoveMouseRelative(-9, 12)
Sleep(5)
MoveMouseRelative(9, -9)
Sleep(5)
until not IsMouseButtonPressed(1)
end
end

Related

how to set (numlock and capslock) for turning on logitech script

hello everyone I want to use "capslock" off or on instead of buttons 4 and 5 to change the first and second code and use "numlock" to activate and deactivate the script, if anyone can please help me this is my script:
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 4 or arg == 5) then
recoil = recoil ~= arg and arg
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 4 then
repeat
MoveMouseRelative(-2, 3)
Sleep(10)
MoveMouseRelative(2, -2)
Sleep(10)
until not IsMouseButtonPressed(1)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 5 then
repeat
MoveMouseRelative(-10, 9)
Sleep(16)
MoveMouseRelative(10, -10)
Sleep(16)
until not IsMouseButtonPressed(1)
end
end
i want to set numlock to turn on and off script. and i want to set when capslock is off script use this:
repeat
MoveMouseRelative(-2, 3)
Sleep(10)
MoveMouseRelative(2, -2)
Sleep(10)
until not IsMouseButtonPressed(1)
and when capslock is on script use
this:
repeat
MoveMouseRelative(-10, 9)
Sleep(16)
MoveMouseRelative(10, -10)
Sleep(16)
until not IsMouseButtonPressed(1)
plz help me if you can . thank you!!
You can determine the current status of lock-keys by invoking function IsKeyLockOn:
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn"numlock" then
if not IsKeyLockOn"capslock" then
-- capslock is off
repeat
MoveMouseRelative(-2, 3)
Sleep(10)
MoveMouseRelative(2, -2)
Sleep(10)
until not IsMouseButtonPressed(1)
else
-- capslock is on
repeat
MoveMouseRelative(-10, 9)
Sleep(16)
MoveMouseRelative(10, -10)
Sleep(16)
until not IsMouseButtonPressed(1)
end
end
end

Is there a function to set two mouse buttons to toggle a script?

I'm working on a recoil script, and I want to be able to activate or toggle it using two mouse buttons at the same time. This is what I have so far. I want to use g4 and g5 to make it work, not just g4
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
end
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
if btn_5_is_pressed then
recoil = not recoil
spot = not spot
else
btn_4_is_pressed = true
end
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
if btn_4_is_pressed then
recoil = not recoil
spot = not spot
else
btn_5_is_pressed = true
end
elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 4) then
btn_4_is_pressed = false
elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 5) then
btn_5_is_pressed = false
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
end
EDIT
Toggle by double-click of mouse button #6:
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
local now = GetRunningTime()
if now - (prev_time or -1000000) < 200 then
prev_time = nil
recoil = not recoil
else
prev_time = now
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end

Lua Logitech How to have script NOT repeat when button is pressed?

I'm trying to have the below code execute the MoveMouseRelative function only once when mouse button 1 is pressed or held. I've tried removing the "repeat" line but it breaks the code. Currently when activated and mouse 1 is held the cursor is dragged down constantly.
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
recoilx2 = not recoilx2
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
if recoilx2 then
repeat
--Sleep(35)
Sleep(5)
MoveMouseRelative(0, 3)
until not IsMouseButtonPressed(1)
end
end
Goal: Lua script for Logitech mouse that performs the following tasks:
When mouse button 5 has been "activated":
- Left clicks once every 1000 milliseconds (time in between shots),
- and also pulls the mouse down once every 1000 milliseconds.
So if I hold left mouse button it continuously shoots but only pulls down when it does shoot
Select a keyboard button you never use in the game and set it as the only way to fire the pistol, this key will be used to fire programmatically.
I assume the key is P, but you can choose any other button: "f12", "backspace", "num9", ...
The game must do nothing on left mouse button press.
local fire_button = "P"
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
-- to prevent mouse buttons from being stuck on
for j = 1, 5 do ReleaseMouseButton(j) end
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
recoilx2 = not recoilx2
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
PressKey(fire_button)
Sleep(50)
ReleaseKey(fire_button)
if recoilx2 then
while IsMouseButtonPressed(1) do
MoveMouseRelative(0, 25)
local next_shot_time = GetRunningTime() + 1000
local LMB
repeat
Sleep(50)
LMB = IsMouseButtonPressed(1)
until not LMB or GetRunningTime() >= next_shot_time
if LMB then
PressKey(fire_button)
Sleep(50)
ReleaseKey(fire_button)
end
end
end
end
end

Combining two Lua scripts?

I'm trying to find a way to combine these two scripts:
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
recoilx2 = not recoilx2
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
if recoilx2 then
repeat
MoveMouseRelative(0, 25)
Sleep(1000)
until not IsMouseButtonPressed(1)
end
end
if IsMouseButtonPressed(1) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
until not IsMouseButtonPressed(1)
end
end
When I press mouse 5 to activate the first section, the repeating click section at the bottom doesn't work.
When I press mouse 5 to activate the first section, the repeating
click section at the bottom doesn't work.
When you press button 5 the first time you end up in this conditional statement
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
recoilx2 = not recoilx2
spot = not spot
end
This will assign true to recoilx2.
When you press button 1 after that you'll end up in this conditional statement:
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
if recoilx2 then
repeat
MoveMouseRelative(0, 25)
Sleep(1000)
until not IsMouseButtonPressed(1)
end
end
Here you wait until button 1 is not pressed anymore.
Unless you press button 5 again to assign false to recoilx2 you'll always end up there when you press button 1 and stay there until you release button 1.
Hence you can never enter this conditional statement.
if IsMouseButtonPressed(1) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
until not IsMouseButtonPressed(1)
end

Is there a function to set two mouse buttons to activate a script?

I'm working on a recoil script, and I want to be able to activate it using left- and right-click.
This is what I have so far. I want to use mb1 and mb2 to make it work, not just mb1.
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
if recoil then
repeat
MoveMouseRelative(-2, 5)
Sleep(10)
MoveMouseRelative(2, -5)
Sleep(21)
until not IsMouseButtonPressed(1)
end
end
end

Resources