I tried to write a script that's just drag your mouse down when right and left mouse button is clicked. Basically it's like norecoil script for shooting game.
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true);
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn"capslock" then
OutputLogMessage("RMB Pressed")
repeat
if IsMouseButtonPressed(1) then
OutputLogMessage("LMB Pressed")
repeat
Sleep(16)
MoveMouseRelative(0, 1)
Sleep(16)
MoveMouseRelative(0, 1)
Sleep(16)
MoveMouseRelative(0, 2)
Sleep(16)
MoveMouseRelative(1, 1)
Sleep(16)
MoveMouseRelative(0, -1)
Sleep(16)
MoveMouseRelative(0, 1)
Sleep(16)
MoveMouseRelative(-2, 2)
until not IsMouseButtonPressed(1)
OutputLogMessage("LMB Released")
end
until not IsMouseButtonPressed(3)
OutputLogMessage("RMB Released")
end
With this code i'm getting OutputLogMessage in script editor but there is no mouse movement at all. I'm kind confused where i could make a mistake?
Here, use this one. Feel free to customize it based on your needs:
local Activate = 3 -- Wheel button to activate/deactivate local
recoil = false -- Disable/Enable script
EnablePrimaryMouseButtonEvents(true); function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == Activate) then
recoil = not recoil if (recoil == false) then
OutputLogMessage("OFF-NoRecoil\n")
OutputLCDMessage("OFF-NoRecoil") else
OutputLogMessage("ON-NoRecoil\n")
OutputLCDMessage("ON-NoRecoil") end end if recoil then antiRecoil(); end end function antiRecoil() repeat -- if mouse1
pressed then MoveMouseRelative(0,5) Sleep(17) until not
IsMouseButtonPressed(1) end
Related
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
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
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
I am trying to make a script for logitech mouse that:
When left mouse button is pressed, it will activate case 1
When holding the right mouse button and pressing the left mouse button, it will activate the case 2
However, no matter how I try it will only work on case 1.
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
-- Case 1: Press only Button 1
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("scrolllock") == false) then
Sleep(77)
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 4)
Sleep(76)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 6)
Sleep(62)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 5)
Sleep(84)
end
--Case 2: Press button 1+2
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("scrolllock") == false) then
Sleep(77)
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 8)
Sleep(76)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 9)
Sleep(62)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 0)
Sleep(84)
end
end
end
I want to add one more case when I press RMB of this script:
When pressed RMB -> press Lshift button
When release RMB -> press Lshift button again
I added the end of the script as below, it does not work.
elseif (event == "MOUSE_BUTTON_PRESSED" and arg==2 and IsKeyLockOn("scrolllock")==false) then
PressAndReleaseKey("lshift")
elseif (event == "MOUSE_BUTTON_RELEASED" and arg==2 and IsKeyLockOn("scrolllock")==false) then
PressAndReleaseKey("lshift")
if I want to add case 3: Press LAlt + LMB, so where do I put IsModifierPressed("lalt") ? I tried as below but failed
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and not IsKeyLockOn("scrolllock")) then
if not IsMouseButtonPressed(3) then -- 3 = Right Mouse Button (it's the same button as arg==2)
-- Case 1: Press only LMB
if IsModifierPressed("lalt") then
-- Case 3: Press LAlt+LMB
else
-- Case 2: Press RMB+LMB
end
elseif ((event == "MOUSE_BUTTON_PRESSED" or event == "MOUSE_BUTTON_RELEASED") and arg==2 and not IsKeyLockOn("scrolllock")) then
PressKey("lshift")
Sleep(50)
ReleaseKey("lshift")
end
end
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and not IsKeyLockOn("scrolllock")) then
if IsModifierPressed("lalt") then
-- Case 3: Press LAlt+LMB
elseif not IsMouseButtonPressed(3) then -- 3 = Right Mouse Button (it's the same button as arg==2)
-- Case 1: Press only LMB
else
-- Case 2: Press RMB+LMB
end
elseif ((event == "MOUSE_BUTTON_PRESSED" or event == "MOUSE_BUTTON_RELEASED") and arg==2 and not IsKeyLockOn("scrolllock")) then
PressKey("lshift")
Sleep(50)
ReleaseKey("lshift")
end
end
You must not have an end before an elseif. The elseif serves as the end of the last if automatically.
I'm surprised this code even compiles and runs at all, as you mentioned, that the first case does work.
Edit: You also do not need to use parentheses around the condition of an if. Since it is already encapsulated by if and then it was not necessary for the langugae design to make those mandatory as in other languages.
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