Lua logitech mouse 180/360 degree turn - lua

As the title says I'm trying to figure out how to get this piece of stolen code to work :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
ReleaseMouseButton(5) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and recoil) then
if recoil then
repeat
Sleep(1)
MoveMouseRelative(-400, 0)
Sleep(1)
until not IsMouseButtonPressed(5)
end
end
end
No matter what sleep timer I add I can't get it to work the way I want : I want a single press pixel perfect 180/360 degree turn in call of duty and not have to hold down the mb5 button in order to turn.

MoveAmount = -400
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(4) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 4) then
for x=1,10,1
do
MoveMouseRelative(MoveAmount, 0)
Sleep(5)
end
end
end

While you're holding down mb5, then every 2 seconds, this line of code is happening:
MoveMouseRelative(-400, 0)
I guess the problem is that moving the mouse -400 pixels isn't exactly a 180 degree turn, and the correct number will probably be different for everyone depending on their mouse sensitivity settings.
You could try some different numbers instead of -400 to see if it works more like what you want.

function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 3) then
recoil = not recoil
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5 and recoil) then
local distance = 400 -- adjust this value
while distance > 0 do
local delta = math.min(100, distance)
distance = distance - delta
MoveMouseRelative(-delta, 0)
Sleep(15)
end
end
end

Related

Lua script for g502

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

LUA scripting no recoil

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

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

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