Sleeptime only works in intervals of 15 - lua

my logitech LUA script used to work flawlessly, but for some reason now i can only adjust "sleeptime" by increments of 15 instead of 1. i used to be able to adjust sleeptime up and down by 1, but now the speed doesn't change unless i adjust 15 times. what am i missing?
sleeptime=15
function OnEvent(event, arg)
EnablePrimaryMouseButtonEvents(true)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("lshift")) then
sleeptime = sleeptime - 1
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("ctrl")) then
sleeptime = sleeptime + 1
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7 and IsModifierPressed("alt")) then
sleeptime = 15
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3)) then
repeat
Sleep(sleeptime)
MoveMouseRelative(3, 3)
Sleep(5)
MoveMouseRelative(-3, 3)
until not IsMouseButtonPressed(1)
end
end

local vertical_speed = 3.0
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 7 then
if IsModifierPressed("lshift") then
vertical_speed = vertical_speed * 1.05 -- increase speed
elseif IsModifierPressed("ctrl") then
vertical_speed = vertical_speed / 1.05 -- decrease speed
else IsModifierPressed("alt")
vertical_speed = 3.0
end
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) then
local frac, x, y = 0, 1
repeat
Sleep(15)
x, y, frac = -x, math.modf(frac + vertical_speed)
MoveMouseRelative(x * 3, y)
until x > 0 and not IsMouseButtonPressed(1)
end
end

Related

Need help on logitech script 2 scripts in 1

im a beginner and need a bit help in combining this 2 Logitech Scripts in 1
this is the first one:
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 == 6) then
PressKey("z", "n")
ReleaseKey("n")
end
if (event =="MOUSE_BUTTON_RELEASED" and arg == 6) then
ReleaseKey("z")
PressAndReleaseKey("n")
end
end
**this is the second one **
keys = {"1", "2", "1", "2"}
i = 1
lastPress = 0
function OnEvent(event, arg)
--OutputLogMessage("event = %s, arg = %s\n", event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 7) then
if(tonumber(GetDate("%y%m%d%H%M%S")) > lastPress +1 ) then
i = 1
end
PressKey(keys[i])
end
if (event == "MOUSE_BUTTON_RELEASED" and arg == 7) then
ReleaseKey(keys[i])
i = i + 1
if(i > table.getn(keys)) then
i = 1
end
lastPress = GetDate("%y%m%d%H%M%S")
end
end
i tried it a lot but when i put both in one then just the second is working - please help me :)
I tried to put both into one but it didnt worked out
As it was said in the comments, "The conditions don't overlap", so just concatenate them all:
local keys = {"1", "2", "1", "2"}
local i = 1
local lastPress = -math.huge
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseKey("z", keys[i])
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
PressKey("z")
PressAndReleaseKey("n")
elseif event =="MOUSE_BUTTON_RELEASED" and arg == 6 then
ReleaseKey("z")
PressAndReleaseKey("n")
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 7 then
if GetRunningTime() > lastPress + 2000 then -- 2 seconds of inactivity
i = 1
end
PressKey(keys[i])
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 7 then
ReleaseKey(keys[i])
i = i % #keys + 1
lastPress = GetRunningTime()
end
end

LGS Lua - turn toggle into hold

Hey i been having some trouble trying to turn this into hold, rn 5 is the trigger key and represents the forward side button on the mouse, i press once to activate and once to turn it off but ideally i would like to turn it into a hold
Offset = 4
Offset_random = 0
Btn_main_switch = 5
Btn_recoil_switch = 4
EnablePrimaryMouseButtonEvents(true)
Is_ads = 0
Enabled = 0
Recoil = 0
Jitter_max = Offset + Offset_random
Jitter_min = Offset - Offset_random
function OnEvent(event, arg)
ClearLog()
OutputLogMessage("Current settings:\n\nJitter = %d\nRecoil = %d\n", Enabled, Recoil)
local recovery_offset
local downcount
local jitter
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Is_ads == 1 and Enabled == 1) then
downcount = 0
repeat
downcount = downcount + 1
if (downcount <= 150 and Recoil == 1) then
MoveMouseRelative(0, 1)
end
jitter = math.random(Jitter_min, Jitter_max)
recovery_offset = -jitter
Sleep(2)
MoveMouseRelative(jitter, jitter)
Sleep(2)
MoveMouseRelative(recovery_offset, recovery_offset)
until not IsMouseButtonPressed(1)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == Btn_main_switch) then
if (Enabled == 0) then
Enabled = 1
else
Enabled = 0
end
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == Btn_recoil_switch) then
if (Recoil == 0) then
Recoil = 1
else
Recoil = 0
end
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 2) then
Is_ads = 1
end
if (event == "MOUSE_BUTTON_RELEASED" and arg == 2) then
Is_ads = 0
end
end
there it is
Replace
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Is_ads == 1 and Enabled == 1) then
with
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Is_ads == 1 and IsMouseButtonPressed(Btn_main_switch) then

Reverse MoveMouseRelative Lua Codding

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 == 5 or arg == 4) then
recoil = recoil ~= arg and arg
elseif event == "MOUSE_BUTTON_PRESSED"
and arg == 1 and recoil == 5 then
MoveMouseRelative(0, -3)
for i = 1, 17 do
MoveMouseRelative(0, 2)
Sleep(15)
if not IsMouseButtonPressed(1) then return end
end
elseif event == "MOUSE_BUTTON_PRESSED"
and arg == 1 and recoil == 4 then
MoveMouseRelative(0, -3)
for i = 1, 35 do
Sleep(15)
MoveMouseRelative(0, 2)
if not IsMouseButtonPressed(1) then return end
end
if not IsMouseButtonPressed(1) then return end
end
end
This is the Lua Script , I wonder how i can get mouse initial position and after it to return to the initial position.
I tried to add MoveMousePosition(x,y)- (32767, 32767 ) at bottom of script but not worked in game . Only on desktop ..
I just want after MoveMouseRelative when i release mouse click to return center or first position .
As Luke100000 said, you need an "undo" movement (the same distance with the opposite sign).
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 == 5 or arg == 4) then
recoil = recoil ~= arg and arg
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 5 then
MoveMouseRelative(0, -3)
local n = 0
for i = 1, 17 do
n = n + 1
MoveMouseRelative(0, 2)
Sleep(15)
if not IsMouseButtonPressed(1) then break end
end
repeat -- wait for LMB release
until not IsMouseButtonPressed(1)
for i = 1, n do
MoveMouseRelative(0, -2)
end
MoveMouseRelative(0, 3)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 4 then
MoveMouseRelative(0, -3)
local n = 0
for i = 1, 35 do
Sleep(15)
n = n + 1
MoveMouseRelative(0, 2)
if not IsMouseButtonPressed(1) then break end
end
repeat -- wait for LMB release
until not IsMouseButtonPressed(1)
for i = 1, n do
MoveMouseRelative(0, -2)
end
MoveMouseRelative(0, 3)
end
end
To undo any operations we need a stack, where you remember everything you did. But since we only have a single position and therefore the order does not matter, we use a simple number to store the total moved x and y instead.
local movedX = 0
local movedY = 0
function move(x, y)
MoveMouseRelative(x, y)
movedX = movedX + x
movedY = movedY + y
end
Now you use e.g. move(0, 2) only.
To undo we do the opposite; since we only have a number by subtracting it.
function undo()
MoveMouseRelative(-movedX, -movedY)
movedX = 0
movedY = 0
end
Unrelated, but in your loop, do not use return but break. That way you can reach the end of the event and add an undo() there.

Logitech LUA script adding sleep timer

Was wondering how to add the sleep timer to my LUA script so it doesn't continually loop as fast as possible and press 0x29, I'd like to make it so when buttons 1 and 3 are pressed on my mouse it hits key 0x29 once every 3-4 seconds instead of as fast as possible.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" then
if (arg == 1 or arg == 2) then
mb1 = IsMouseButtonPressed(1);
mb2 = IsMouseButtonPressed(3);
--OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2));
if (mb1 == true and mb2 == true) then
PressAndReleaseKey(0x29);
end
end
end
end
You can get the current time in milliseconds by GetRunningTime()
local last_time = -math.huge
local is_pressed = {}
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "MOUSE_BUTTON_RELEASED" and (arg == 1 or arg == 2) then
is_pressed[arg] = false
elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 1 or arg == 2) then
is_pressed[arg] = true
local mb1 = is_pressed[1]
local mb2 = is_pressed[2]
--OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2))
if mb1 and mb2 and GetRunningTime() - last_time > 5000 then
PressAndReleaseKey(0x29)
last_time = GetRunningTime()
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

Resources