My AHK script is not working as intended: pause/unpause & autoclicker

Ask gaming related questions (AHK v1.1 and older)
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

My AHK script is not working as intended: pause/unpause & autoclicker

11 Apr 2024, 04:34

How the code suppose to works is that
* When it starts the code pauses/suspend.
* When I press the "\" key it unpause/unsuspend.
* Every time LButton is press/activated it adds +1 to a variable, unless the AltLmb variable == 1 which resets the AltLmb and a's value to 0.(When holding LButton; +1 to a variable from the start and +1 to a variable for every 0.4s until released)
* When a value == 4 then AltLmb = 1
* When you press LButton together with "s" key while AltLmb == 1 then; LShift is activated -> LButton -> (while s is press) -> LShift again.(also stop holding s when I stopped holding s)
* And if you press f then after a few hundred milisecond activate LButton unless AltLmb == 1

Other things needed:
* After unpausing/unsuspending resets a and AltLmb variable to 0

Also you can change the variable a's name to Value01

Code: Select all

#MaxThreadsPerHotkey 5
Pause, on
a := 0
LmbVar := a
AltLmb := 0
spin := 0

\::Pause

LButton:: ; When Left mouse button is pressed
{
    If (AltLmb == 1) ; if AltLmb is equal to 1 then set AltLmb and a equals to 0
    {
        AltLmb := 0
        a := 0
    } 
    If (AltLmb == 0) ; if AltLmb is equal to 0 then add +1 to a
    {
        LmbVar := a++
    }
    SendInput, {LButton} ; Send a mouse click
}

If (a == 4)
{
    AltLmb := 1
}

f::
{
    Send, f
    Sleep, 200
    If (AltLmb == 0)
    {
        SendInput, {LButton}
        LmbVar := a++
    }
}

; Spin 180 When AltLmb is equal to 1 and the Left mouse button and d key is pressed
LButton & s::
{
    If (AltLmb == 1)
    {
    SendInput, {LShift}
	Send, {s down}
	SendInput, {LButton}
	SendInput, {LShift}
	Send, {s up}
    }
}

return

[Mod action: Moved topic to the v1 section since this is v1 code. The main section is for v2.]
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended

11 Apr 2024, 05:46

Welcome to this AutoHotkey forum!

I suggest that you change the subject of this thread. Instead of indicating that you need help, provide the topic of the problem itself. See the forum for examples of informative subjects.

You need an approach to writing and troubleshooting your script. Instead of starting with seven problems, I typically start with one. Get one step working. You can then move to other steps. Examine the AHK documentation along the way. The demonstration script below illustrates the following.
  1. Hotkey subroutines are not bound by braces, but they typically end with a Return command. This command has a specific effect on a script.
  2. The tilde unblocks the key's native function.
  3. You can understand your variables by displaying, logging, or inspecting their values.

Code: Select all

#Requires AutoHotkey v1.1.33.11
Gosub Reset
Update:
ToolTip % "AltLmb = "     AltLmb "`n"
        . "a          = " a
Return

~LButton::
If (AltLmb = 1)
 Gosub Reset
If (AltLmb = 0)
 a++
If (a = 4)
 AltLmb := 1
Gosub Update
Return

Reset:
AltLmb := a := 0
Return
Pause and Suspend differ. I have provided the links here so that you can learn more.

More homework: $ prefixCustom combinations

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

Best of luck!
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended

11 Apr 2024, 09:28

Thanks also how can you tell and whats the difference of 1v and 2v of AHK?
And my new code's "~g & ~s::" does not work. How can I make it work or is there another problem?

New Code:

Code: Select all

#MaxThreadsPerHotkey 5
Pause on
a := 0
AltLmb := 0
f := 0
s := 0
l := 0


Gosub Reset
Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

~g::
;~LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
If (a = 4)
    AltLmb := 1
Gosub Update
Return

Reset:
AltLmb := a := 0
Return

~f::
;Send, f
    f++
Gosub Update
    Sleep 1000
    f--
If (AltLmb == 0)
;SendInput, {LButton}
    LmbVar := a++
Gosub Update
return

~g & ~s::
;LButton & s::
If (AltLmb == 1)  
    s++
Gosub Update
    Sleep 1000
    l++
    s--
Gosub Update
    Sleep 1000
    l--
;SendInput, {LShift}
;Send, {s down}
;SendInput, {LButton}
;SendInput, {LShift}
;Send, {s up}
Gosub Update
return
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended

11 Apr 2024, 10:30

V2 vs. V1

If your script starts paused, then the commands at the top will not execute, right?

"Does not work" says neither what your script does, nor what it should do. Imagine that you take your car into a car repair shop. The mechanic says, "How may I help you?" You reply, "The car does not work." Is that enough?
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended

11 Apr 2024, 21:07

*I found the problem and its fix now.

The problem I have is when I press both s and g the script for ~s & ~g:: does not activate

I fixed the problem by doing

Code: Select all

~s & g::
Now I have a new problem. The script below still activates even when the condition of the If statement is not yet achieved.(For the "~s & g::" script)

Code: Select all

#MaxThreadsPerHotkey 5
a := 0
AltLmb := 0
f := 0
s := 0
l := 0

Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

Reset:
AltLmb := a := 0
Return

;-----The_Problemactic_One-----
~s & g::
;LButton & s::
If (AltLmb == 1)  
    s++
    Gosub Update
    Sleep 1000
    l++
    s--
    Gosub Reset
    Gosub Update
    Sleep 1000
    l--
Gosub Update
return
(For the "~s & g::" script):
When AltLmb is not yet equal to 1. It skips s++ line but not the rest of the script.
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended

11 Apr 2024, 22:36

Indenting means nothing. Braces denote a code block.
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended

12 Apr 2024, 04:15

Its fixed now

Code: Select all

#MaxThreadsPerHotkey 5
Suspend on
a := 0
AltLmb := 0
f := 0
s := 0
l := 0

\::
Suspend
return

Gosub Reset
Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

AltCheck:
If (a = 3)
    AltLmb := 1
return

~LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
Return

~f::
Send, f
    f++
Gosub Update
    Sleep 200
    f--
If (AltLmb == 0)
{
    SendInput, {LButton}
    LmbVar := a++
}
Gosub AltCheck
Gosub Update
return

~s & LButton::
If (AltLmb == 1)  
{
    SendInput, {LShift}
    s++
    SendInput, {s down}
    l++
    Gosub Update
    Sleep 100
    SendInput, {LShift}
    s--
    l--
}
Gosub AltCheck
Gosub Update
return

$q::
SendInput, {q}
If (AltLmb == 0)  
{
        AltLmb := 1
        a := 3
}
Gosub Update
return
.

* Also is there a way to add a timer/cooldown in the script where I have to wait before I can activate the commands again? While being able to active another
command within the script while one of the command is in cooldown.

(Ex.: I pressed Q then it activated the command below the "q::" and there's a 5s cooldown before I can activate the command again. And while the Q script is in cooldown I pressed LButton and so the command below the "~LButton::" activates even during the Q script is in cooldown.)
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended

12 Apr 2024, 05:41

Cooldown for multiple hotkeys

Code: Select all

; This script demonstrates a cooldown period for multiple hotkeys
#Requires AutoHotkey v1.1.33.11
#UseHook
Global cooling := {}       ; {hotkey: end of cooldown period}

#If !cooling(A_ThisHotkey) ; Adding this line checks for cooldown
q::SendInput % "{Text}`n" A_Now " " A_ThisHotkey "`n"
r::SendInput % "{Text}`n" A_Now " " A_ThisHotkey "`n"

cooling(hk) {              ; Assess or set cooldown
 Static wait := 4000       ; Cooldown period in milliseconds
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
This requires no alterations to the default maximum number of threads per hotkey.

This script does not block keys being cooled, but the script could be adjusted to accommodate that if needed. The script prevents the hotkey subroutines from executing during the cooldowns.
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended

15 Apr 2024, 23:23

I finally realized that I need to create more Global Cooling variables

Here it is

Code: Select all

#SingleInstance
#MaxThreadsPerHotkey 5
#UseHook
Suspend on
Global cooling := {}
Global cooling1 := {}
Global cooling2 := {}
a := 0
AltLmb := 0
f := 0
s := 0
l := 0

\::
Suspend
return

Gosub Reset
Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

AltCheck:
If (a = 3)
    AltLmb := 1
return

#If !cooling(A_ThisHotkey)

~LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 800
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
Return

Reset:
AltLmb := a := 0
Return

#If !cooling1(A_ThisHotkey)

~f::
Send, f
    f++
Gosub Update
    f--
If (AltLmb == 0)
{
    Sleep 200
    SendInput, {LButton}
    a++
}
Gosub AltCheck
Gosub Update
cooling1(hk) {
 Static wait := 5000
 now := A_TickCount
 If cooling1.HasKey(hk) && cooling1[hk] > now
  Return True
 cooling1[hk] := now + wait
}
return

~s & LButton::
If (AltLmb == 1) 
 {
    SendInput, {LShift}
    s++
    SendInput, {s down}
    l++
    Gosub Update
    Sleep 100
    SendInput, {LShift}
    s--
    l--
}
Gosub AltCheck
Gosub Update
return

#If !cooling2(A_ThisHotkey)

~q::
If (AltLmb == 0) 
 {
        AltLmb := 1
        a := 3
}
Gosub Update
cooling2(hk) {
 Static wait := 5000
 now := A_TickCount
 If cooling2.HasKey(hk) && cooling2[hk] > now
  Return True
 cooling2[hk] := now + wait
}
return
The last thing I need is to have the LButton be automatically clicked for every 0.4s when I'm holding the LButton down
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended

15 Apr 2024, 23:35

You could try SetTimer. For disabling the timer, you may want to add an "Up" hotkey modifier to a new hotkey for ~LButton, so that this will be triggered when the button is released.

Code: Select all

#Requires AutoHotkey v1.1.33.11

~LButton::   SetTimer Clik, 400
~LButton Up::SetTimer Clik, Off

Clik:
Click
Return
Incorporating this into your script is likely to be straightforward.
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended

16 Apr 2024, 08:23

The auto clicker is working fine when holding the LButton down but when I spam it, the auto clicker still activates. It only stops by clicking once but sometimes it doesn't stop so I need to click multiple times.

Code:

Code: Select all

AltCheck:
If (a = 3)
    AltLmb := 1
If (a > 3)
    Gosub Reset
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 400
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
{                               ; --------------------------------------Where the auto clicker code starts--------------------------------------
    SendInput, {LButton}
    SetTimer Clik, 400
}
Return

~LButton Up::SetTimer Clik, Off

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
Return
.
I tried to add the "If (LButton down)" but the auto clicker won't work
And if I add another "~LButton::". It would give me a duplicate hotkey error
.

Code: Select all

AltCheck:
If (a = 3)
    AltLmb := 1
If (a > 3)
    Gosub Reset
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 400
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
If (LButton down) ;--------------------------------------I add this but its not working--------------------------------------
{
    SendInput, {LButton}
    SetTimer Clik, 400
}
Return

~LButton Up::SetTimer Clik, Off

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
Return
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended: pause/unpause & autoclicker

16 Apr 2024, 11:38

You may need to check the timing. I am not sure what would happen if your "Up" hotkey is triggered before your "Down" hotkey subroutine is completed. You can explore it and find out.
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended: pause/unpause & autoclicker

17 Apr 2024, 22:30

I added "KeyWait"
works fine now but when I click, release then hold the LButton within a short time The auto clicker won't work. I need to wait for around 0.4s for the auto clicker to work again when holding after clicking the button.

LButton code:

Code: Select all

Global cooling := {}

AltCheck:
If (a = 3)
    AltLmb := 1
If (a > 3)
    Gosub Reset
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 400
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
    SendInput, {LButton}
KeyWait, LButton, D
    SetTimer Clik, 400
KeyWait, LButton, U
    SetTimer Clik, Off
Return

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
Return
-
Main code:
-

Code: Select all

#SingleInstance
#MaxThreadsPerHotkey 5
#UseHook
Suspend on
Global cooling := {}
Global cooling1 := {}
Global cooling2 := {}
a := 0
AltLmb := 0
f := 0
s := 0
l := 0

\::
Suspend
return

Gosub Reset
Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

AltCheck:
If (a = 3)
    AltLmb := 1
If (a > 3)
    Gosub Reset
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 400
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
    SendInput, {LButton}
KeyWait, LButton, D
    SetTimer Clik, 400
KeyWait, LButton, U
    SetTimer Clik, Off
Return

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
Return

#If !cooling1(A_ThisHotkey)

~*f::
Send, f
    f++
Gosub Update
    f--
If (AltLmb == 0)
{
    Sleep 200
    SendInput, {LButton}
    a++
}
Gosub AltCheck
Gosub Update
cooling1(hk) {
    Static wait := 250
    now := A_TickCount
    If cooling1.HasKey(hk) && cooling1[hk] > now
     Return True
    cooling1[hk] := now + wait
   }
return

~s & LButton::
If (AltLmb == 1) 
 {
    SendInput, {LShift}
    s++
    SendInput, {s down}
    l++
    Gosub Update
    Sleep 100
    SendInput, {LShift}
    s--
    l--
}
Gosub AltCheck
Gosub Update
return

#If !cooling2(A_ThisHotkey)

~*q::
If (AltLmb == 0) 
 {
        AltLmb := 1
        a := 3
}
Gosub Update
cooling2(hk) {
 Static wait := 4900
 now := A_TickCount
 If cooling2.HasKey(hk) && cooling2[hk] > now
  Return True
 cooling2[hk] := now + wait
}
return
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended: pause/unpause & autoclicker

18 Apr 2024, 05:55

What the script does:
Is there a way to add a timer/cooldown in the script where I have to wait before I can activate the commands again?
The #If directive indicates that a hotkey is active when not being cooled. It applies to hotkeys and hotstrings below the directive-- until the next #If. See documentation for details about #If. You can move the directive to be elsewhere, and can "disable" it if you wish, too (i.e., make all subsequent hotkeys always active).
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended: pause/unpause & autoclicker

18 Apr 2024, 21:49

I was hoping it would automatically do the auto-click after the cooldown.
I don't really need to fix that. Fixing it is mostly for foolproofing the A variable value to be in the same stat value as in the game

The coding is mostly done anyway.

I think the last thing I need is to complete the "~s & LButton::" program.

*Is there a way to check if the user pressed {s} and {LButton} while a certain variable is equal to 1 and moving the mouse cursor to a certain distance to the left or right?
* - so that I can used it to check when I want to turn 180 degree after pressing {S} and {LButton} while AltLmb is == 1.
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended: pause/unpause & autoclicker

19 Apr 2024, 05:35

Code: Select all

#Requires AutoHotkey v1.1.33.11
SLOW   := 0    ; Mouse speed (0=fastest, 100=slowest)
AltLmb := True
; AltLmb := False

#If AltLmb
~s & LButton::
While GetKeyState("LButton", "P")
 MouseMove 100, 0, SLOW, R
Return
#If
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended: pause/unpause & autoclicker

23 Apr 2024, 01:35

Heres the new and completed ~s&LButton::

Code: Select all

Fast := 0
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
MouseOffSet := 100
TurnRange := 100
NegMouseOffSet := (MouseOffSet*(-1))

AimOffSet:
MouseGetPos, xpos
CenterCoordinateZero := (xpos-960)
Return

#if ALmb

~s & LButton::
Sleep 200
Gosub AimOffSet
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
If (CenterCoordinateZero >= MouseOffSet) 
 {
    MouseMove TurnRange, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove RightBack, 0, Fast, R
}
If (CenterCoordinateZero <= NegMouseOffSet) 
 {
    MouseMove LeftSpin, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove LeftBack, 0, Fast, R
}
Gosub AltCheck
Gosub Update
return
~
Main Code:
~

Code: Select all

#SingleInstance
#MaxThreadsPerHotkey 5
#UseHook

Suspend on
Global cooling := {}
Global cooling1 := {}
Global cooling2 := {}
a := 0
AltLmb := 0
f := 0
s := 0
l := 0
Fast := 0
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
MouseOffSet := 100
TurnRange := 100
NegMouseOffSet := (MouseOffSet*(-1))

AimOffSet:
MouseGetPos, xpos
CenterCoordinateZero := (xpos-960)
Return

\::
Suspend
return

Gosub Reset

u::
Gosub AimOffSet
ToolTip % "X = " CenterCoordinateZero
Return

Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
        . "F = " f "`n"
        . "Shift = " s "`n"
        . "lmb = " l
Return

AltCheck:
If (a = 3)
    AltLmb := 1
    ALmb := True
If (a > 3)
    Gosub Reset
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := 400
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
    SendInput, {LButton}
KeyWait, LButton, D
    SetTimer Clik, 400
KeyWait, LButton, U
    SetTimer Clik, Off
Return

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

Reset:
AltLmb := a := 0
ALmb := False
Return

#If !cooling1(A_ThisHotkey)

~*f::
Send, f
    f++
Gosub Update
    f--
If (AltLmb == 0)
{
    Sleep 200
    SendInput, {LButton}
    a++
}
Gosub AltCheck
Gosub Update
cooling1(hk) {
    Static wait := 250
    now := A_TickCount
    If cooling1.HasKey(hk) && cooling1[hk] > now
     Return True
    cooling1[hk] := now + wait
   }
return

#if ALmb

~s & LButton::
Sleep 200
Gosub AimOffSet
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
If (CenterCoordinateZero >= MouseOffSet) 
 {
    MouseMove TurnRange, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove RightBack, 0, Fast, R
}
If (CenterCoordinateZero <= NegMouseOffSet) 
 {
    MouseMove LeftSpin, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove LeftBack, 0, Fast, R
}
Gosub AltCheck
Gosub Update
return

#If !cooling2(A_ThisHotkey)

~*q::
If (AltLmb == 0) 
 {
        AltLmb := 1
        a := 3
}
Gosub Update
cooling2(hk) {
 Static wait := 4900
 now := A_TickCount
 If cooling2.HasKey(hk) && cooling2[hk] > now
  Return True
 cooling2[hk] := now + wait
}
return

;-------Settings-------
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended: pause/unpause & autoclicker

23 Apr 2024, 02:41

New problem
Pressing Q refreshes the LMB cooldown to 100ms in the game
Idk how to do that with the code
I always getting an error when I'm trying something to do that. Like duplication function error, cant label functions errors and stuff
User avatar
mikeyww
Posts: 27009
Joined: 09 Sep 2014, 18:38

Re: My AHK script is not working as intended: pause/unpause & autoclicker

23 Apr 2024, 06:38

I did not test your script. If you would like to create a hotkey for a different context, such as #If cooling2(A_ThisHotkey), then you would place such a directive before the first hotkey in that context. The #If directive applies to all hotkeys and hotstrings below it, until the next such directive. An alternative to having such variants would be using no directive (no context) but using If... Else in the hotkey subroutine. You would be checking for the same condition there, and acting differently according to the condition.

Code: Select all

; Pseudocode here
#If
~*q::
If cooling... {
  change the cooling time
} Else {
  do abc
}
Return
ReyAHK
Posts: 13
Joined: 11 Mar 2021, 09:21

Re: My AHK script is not working as intended: pause/unpause & autoclicker

23 Apr 2024, 09:50

i tried doing this

Code: Select all

~*q::
If (AltLmb == 0) 
 {
        AltLmb := 1
        a := 3
}
Gosub Update
cooling2(hk) {
 Static wait := QAbilityCD
 now := A_TickCount
 If cooling2.HasKey(hk) && cooling2[hk] > now
  Return True
 cooling2[hk] := now + wait
}
LmbCD := 100
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := LmbCD
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
    SendInput, {LButton}
KeyWait, LButton, D
    Settimer, Clik, % LmbCD
KeyWait, LButton, U
    SetTimer Clik, Off

Sleep 10
LmbCD := (CooldownOfLmb*1000)
Return
But the cooldown code cant read variable "LmbCD". I don't know I how I can do so.

Also here's the entire code:

Code: Select all

#SingleInstance
#MaxThreadsPerHotkey 5
#UseHook

Suspend on
Global cooling := {}
Global cooling1 := {}
Global cooling2 := {}

;-------Settings-------


MouseOffSet := 100 ;Mouse coordinate offset before spinning 180
TurnRange := 100 ;Range spin
Fast := 0 ;Speed of the turn
MonitorResolution := 1920 ;Resolution of the monitor

;-Cooldown-

CooldownOfLmb := 0.5 ;Lmb cooldown in seconds
CooldownOfQ := 5 ;Q cooldown in seconds


;-------End_of_Settings-------
a := 0
AltLmb := 0
LmbCD := (CooldownOfLmb*1000)
QAbilityCD := (CooldownOfQ*1000)
HalfOfMonitorResolution := (MonitorResolution / 2)
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
NegMouseOffSet := (MouseOffSet*(-1))

AimOffSet:
MouseGetPos, xpos
CenterCoordinateZero := (xpos-HalfOfMonitorResolution)
Return

\::
Suspend
return

Gosub Reset

u::
Gosub AimOffSet
ToolTip % "X = " CenterCoordinateZero
Return

Update:
ToolTip % "AltLmb = " AltLmb "`n"
        . "a = " a "`n"
Return

AltCheck:
If (a = 3)
    AltLmb := 1
    ALmb := True
If (a > 3)
    Gosub Reset
return

Reset:
AltLmb := a := 0
ALmb := False
Return

Clik:
SendInput,{LButton} 
a++
Gosub AltCheck
Gosub Update
Return

#If !cooling1(A_ThisHotkey)

~*f::
Send, f
If (AltLmb == 0)
{
    Sleep 200
    SendInput, {LButton}
    a++
}
Gosub AltCheck
Gosub Update
cooling1(hk) {
    Static wait := 300
    now := A_TickCount
    If cooling1.HasKey(hk) && cooling1[hk] > now
     Return True
    cooling1[hk] := now + wait
   }
return

#if ALmb

~s & LButton::
Sleep 200
Gosub AimOffSet
LeftSpin := (-1*TurnRange)
LeftBack := ((-1*CenterCoordinateZero)+TurnRange)
RightBack := (-1*(CenterCoordinateZero+TurnRange))
If (CenterCoordinateZero >= MouseOffSet) 
 {
    MouseMove TurnRange, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove RightBack, 0, Fast, R
}
If (CenterCoordinateZero <= NegMouseOffSet) 
 {
    MouseMove LeftSpin, 0, Fast, R
    Sleep 10
    SendInput, {LButton}
    a++
    Sleep 100
    MouseMove LeftBack, 0, Fast, R
}
Gosub AltCheck
Gosub Update
return

#If !cooling2(A_ThisHotkey)

~*q::
If (AltLmb == 0) 
 {
        AltLmb := 1
        a := 3
}
Gosub Update
cooling2(hk) {
 Static wait := QAbilityCD
 now := A_TickCount
 If cooling2.HasKey(hk) && cooling2[hk] > now
  Return True
 cooling2[hk] := now + wait
}
LmbCD := 100
return

#If !cooling(A_ThisHotkey)

~*LButton::
If (AltLmb = 0)
    a++
If (AltLmb = 1)
    Gosub Reset
Gosub AltCheck
Gosub Update
cooling(hk) {
 Static wait := LmbCD
 now := A_TickCount
 If cooling.HasKey(hk) && cooling[hk] > now
  Return True
 cooling[hk] := now + wait
}
    SendInput, {LButton}
KeyWait, LButton, D
    Settimer, Clik, % LmbCD
KeyWait, LButton, U
    SetTimer Clik, Off

Sleep 10
LmbCD := (CooldownOfLmb*1000)
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Playa 01 and 65 guests