I want to be able press and hold my G5 key on Logitech G910 keyboard to move to xy, click then move to another xy, spam click until I release G5 and then have it move to another xy and click once more before ending
if (event == "G_PRESSED" and arg == 5 and GetMKeyState("kb") == 3) then
MoveMouseTo( 52250, 46464)
Sleep(math.random(25, 40))
PressMouseButton(1)
ReleaseMouseButton(1)
Sleep(math.random(25, 40))
MoveMouseTo( 51841, 48832)
Sleep(360)
repeat
PressMouseButton(1)
Sleep(math.random(25, 40))
ReleaseMouseButton(1)
Sleep(math.random(25, 40))
until "G_RELEASED" and arg == 5
Sleep(math.random(25, 40))
MoveMouseTo( 52250, 46464)
Sleep(math.random(25, 40))
PressMouseButton(1)
ReleaseMouseButton(1)
end
I got it working up until the point of the G_RELEASED part it will stop spam clicking but will not move on to the next xy, click.
I did try a few other things where the until G_RELEASED bit as well but just resulted in a continuous spam clicking which I couldn't get to stop without restarting the computer
Related
I got this code that makes my mouse drag down if i press mouse 5 while numlock is active, but i want to make my mouse go right and press D at same time for half a second then switch to mouse left and press A at same time and keep repeating this untill i stop pressing mouse5 --- Mouse 5 is IsMouseButtonPressed(5) if youre not familiar with the API
function OnEvent(event, arg)
if IsKeyLockOn("numlock" )then
if IsMouseButtonPressed(5) then
repeat
MoveMouseRelative(0,5)
Sleep(5)
until not IsMouseButtonPressed(1)
end
end
end
How do i make it
Try this code:
local keydir = {[-1]="A", [1]="D"}
local speed = 1
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 and IsKeyLockOn("numlock") then
local dir = -1
repeat
dir = -dir
local time0 = GetRunningTime()
repeat
MoveMouseRelative(dir*speed, 0)
Sleep(15)
until GetRunningTime() - time0 > 500
PressAndReleaseKey(keydir[dir])
Sleep(15)
until not IsMouseButtonPressed(5)
end
end
So basically, this is what my script looks like at the moment, it’s a rapid fire macro and reduces the recoil of the guns, however I can never spray with this script for some reason as it’s very slow because I guess it’s reducing the recoil. I was wondering if I could shoot like 4, 5 bullets without any recoil (only auto shoot while holding mouse 3 not while tapping.) and continue with spray like normal spray without any delays while already holding mouse3. So 4 bullets no recoil and rest the regular spray on the same cycle. If that makes any sense. Any help would be greatly appreciated.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("scrolllock")then
if IsMouseButtonPressed(3) then
repeat
if IsMouseButtonPressed(3) then
repeat
PressMouseButton(1)
Sleep(15)
ReleaseMouseButton(1)
until not IsMouseButtonPressed(3)
end
until not IsMouseButtonPressed(3)
end
end
end
local rapid_fire_delay = 15 -- delay between simulation of LMB press/release
local LMB_Pressed
do -- initializing PRNG
local dt = 0
for c in GetDate():gmatch"." do
dt = (dt % 65537 * 23456 + c:byte())
end
math.randomseed(dt)
end
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("scrolllock") then -- RMB press
for j = 1, math.random(4, 5) do -- first 4-5 bullets as rapid-fire
PressMouseButton(1)
Sleep(math.random(rapid_fire_delay, 2*rapid_fire_delay))
ReleaseMouseButton(1)
Sleep(math.random(rapid_fire_delay, 2*rapid_fire_delay))
if not IsMouseButtonPressed(3) then return end -- is RMB pressed?
end
PressMouseButton(1)
LMB_Pressed = true
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 2 and LMB_Pressed then -- RMB release
ReleaseMouseButton(1)
LMB_Pressed = false
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
repeat
Sleep(15)
PressKey("SPACEBAR")
Sleep(15)
ReleaseKey("SPACEBAR")
until not IsMouseButtonPressed(5)
end
end
The line for j = 1, math.random(4, 5) do means "a random quantity from 4 to 5 bullets".
If you want exactly 3 bullets change this line to for j = 1, 3 do
EDIT:
This is instruction on how to make the rapidfire turn on only after LMB double-click.
Usual slow LMB click will not trigger rapidfire.
local Prev_LMB_Time, LMB_Pressed = 0
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
if IsKeyLockOn("scrolllock") then
local tm = GetRunningTime()
tm, Prev_LMB_Time = tm - Prev_LMB_Time, tm
if tm < 200 then -- LMB double-click
for j = 1, 100 do
PressMouseButton(1)
Sleep(1)
ReleaseMouseButton(1)
Sleep(1)
if not IsMouseButtonPressed(4) then return end
end
end
end
PressMouseButton(1)
LMB_Pressed = true
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 and LMB_Pressed then
ReleaseMouseButton(1)
LMB_Pressed = false
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
repeat
Sleep(15)
PressKey("SPACEBAR")
Sleep(15)
ReleaseKey("SPACEBAR")
until not IsMouseButtonPressed(5)
end
end
Currently you have in GHUB:
Primary Click = G1
Back = G4 G8
What you should do in GHUB (in this order):
Bind "Primary Click" to G8 (from now on, use button#8 instead of LMB)
Bind "Back" to G1
Set the script
Now you should have the following:
Primary Click = G8
Back = G1 G4
Mouse button#8 is now "spare LMB" just in case LMB works incorrectly.
How can I make it so when i hold left alt and left mouse it just holds down the "L" key and then when I release left alt it goes back to the auto click script
thanks.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsMouseButtonPressed(1) then
repeat
PressKey("L")
Sleep(math.random(15, 45))
ReleaseKey("L")
Sleep(math.random(15, 45))
until not IsMouseButtonPressed(1)
end
end
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
repeat
PressKey("L")
Sleep(math.random(15, 45))
while IsModifierPressed("lalt") do
Sleep(10)
end
ReleaseKey("L")
Sleep(math.random(15, 45))
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
Is there a way to shorten this code?
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
PressKey ("a")
Sleep (50)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
PressKey ("a")
Sleep (200)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
...
next all the same with sleep values only changing
I want to use the repeat-until, but I cant do that as the value for sleep is changing. Is there a way to save the sleep values in a table (ie. 50, 200, 100, 75, 25, 200) so I can use the Repeat-Until in the code? I've been trying to search but I am new to Lua. Any help is appreciated, thanks
Since you want to loop over a range of timeouts I wouldn't use repeat until but rather a for loop. Most importantly you should notify the caller that all timeouts failed after finishing the list.
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1) then
for _,duration in ipairs{50, 200, 100, 75, 25, 200} do
PressKey ("a")
Sleep (duration)
if not IsMouseButtonPressed(1) then
ReleaseKey ("a")
return
end
end
return "ERROR" -- You should somehow indicate timeout to the caller
end