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
i'm trying to make a script for my mouse for a game . Basically this is what it has to do:
when num lock is OFF he must press the q key every time right mouse and left mouse clicked are simultaneously
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
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
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
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
so i have a problem with a LUA Script that im currently building. I have variable for a Gun Spray Pattern, but i want to add a 9ms delay between the Coordinates, unfortunately i cant find a vay to add delays to between the coordinates. Its should look like this
{x=2,y=2}DELAY{x=1,y=1}DELAY......
I know that its impossible to put delays in Variables but i would hope to find a way to put the delays in a loop maybe??.
Heres the code:
local Macro_Activation_Key = 4
local Selection_Key = 3
local Spray_Randomize1 = math.random(24,24)
local Spray_Randomize2 = math.random(20,20.5)
local Spray_Randomize3 = math.random(24,24)
local Recoil_Activator
R_Weapon_Selector = false,0
EnablePrimaryMouseButtonEvents(true);
local AK47_Pattern = {{x=0,y=2},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=4},{x=0,y=4},{x=0,y=5},{x=0,y=8},{x=0,y=8},{x=0,y=8}}
local M4A1_Pattern = {{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=-1,y=4},{x=-1,y=4},{x=0,y=5},{x=-1,y=5},{x=-1,y=5},{x=0,y=5},{x=0,y=5},{x=0,y=5}}
local function RetrieveWeaponName(weapon,act) if weapon == 1 then
return"AK47" elseif weapon == 3 then
return"M4A1" end if act then
return"ON_Macro" else return"OFF_Macro" end end
local function OutputLogs(weapon, act)
OutputLogMessage(RetrieveWeaponName(weapon,act).."\n");
OutputDebugMessage(RetrieveWeaponName(weapon,act).."\n");
ClearLCD();
OutputLCDMessage(RetrieveWeaponName(weapon,act));
end function
OnEvent(event, arg) if (event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key) then
Recoil_Activator = not Recoil_Activator OutputLogs(nil,Recoil_Activator) end
if Recoil_Activator then
if (event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key) then
if R_Weapon_Selector >= 3 then R_Weapon_Selector = 0 end R_Weapon_Selector = R_Weapon_Selector + 1 OutputLogs(R_Weapon_Selector,nil) end if (R_Weapon_Selector == 1) and IsMouseButtonPressed(1) then
for i = 1, #AK47_Pattern do if IsMouseButtonPressed(1) then Sleep(Spray_Randomize1) MoveMouseRelative( AK47_Pattern[i].x, AK47_Pattern[i].y ) end end end
if (R_Weapon_Selector == 3) and IsMouseButtonPressed(1) then for i = 1, #M4A1_Pattern do if IsMouseButtonPressed(1) then Sleep(Spray_Randomize3) MoveMouseRelative( M4A1_Pattern[i].x, M4A1_Pattern[i].y )
I want to add Delay to the local AK47_Pattern and M4a1_Pattern Variables.
Appreciate all kinds of help
end end end end end
local Macro_Activation_Key = 4
local Selection_Key = 3
local Recoil_Activator, R_Weapon_Selector = false,0
EnablePrimaryMouseButtonEvents(true)
-- d = delay to wait before moving the mouse (d=9 by default)
local AK47_Pattern = {{x=0,y=2},{d=11,x=0,y=2},{d=12,x=0,y=2},{x=0,y=3},{x=0,y=4},{x=0,y=4},{x=0,y=5},{x=0,y=8},{x=0,y=8},{x=0,y=8}}
local M4A1_Pattern = {{x=0,y=1},{d=5,x=0,y=1},{d=7,x=0,y=2},{x=0,y=2},{x=0,y=1},{x=0,y=1},{x=0,y=2},{x=0,y=2},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=0,y=3},{x=-1,y=4},{x=-1,y=4},{x=0,y=5},{x=-1,y=5},{x=-1,y=5},{x=0,y=5},{x=0,y=5},{x=0,y=5}}
local function RetrieveWeaponName(weapon,act)
if weapon == 1 then
return"AK47"
elseif weapon == 3 then
return"M4A1"
end
if act then
return"ON_Macro"
else
return"OFF_Macro"
end
end
local function OutputLogs(weapon, act)
OutputLogMessage(RetrieveWeaponName(weapon,act).."\n")
OutputDebugMessage(RetrieveWeaponName(weapon,act).."\n")
ClearLCD()
OutputLCDMessage(RetrieveWeaponName(weapon,act))
end
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key) then
Recoil_Activator = not Recoil_Activator
OutputLogs(nil,Recoil_Activator)
end
if Recoil_Activator then
if (event == "MOUSE_BUTTON_PRESSED" and arg == Selection_Key) then
if R_Weapon_Selector >= 3 then
R_Weapon_Selector = 0
end
R_Weapon_Selector = R_Weapon_Selector + 1
OutputLogs(R_Weapon_Selector,nil)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
if R_Weapon_Selector == 1 then
for i = 1, #AK47_Pattern do
Sleep(AK47_Pattern[i].d or 9)
MoveMouseRelative( AK47_Pattern[i].x, AK47_Pattern[i].y )
if not IsMouseButtonPressed(1) then
break
end
end
end
if R_Weapon_Selector == 3 then
for i = 1, #M4A1_Pattern do
Sleep(M4A1_Pattern[i].d or 9)
MoveMouseRelative( M4A1_Pattern[i].x, M4A1_Pattern[i].y )
if not IsMouseButtonPressed(1) then
break
end
end
end
end
end
end