Reload Issues

Ask gaming related questions (AHK v1.1 and older)
MonkeyMode
Posts: 10
Joined: 14 Feb 2021, 10:42

Reload Issues

Post by MonkeyMode » 26 May 2023, 11:04

I need to reload frequently when using this script, however when I press my Reload hotkey, it only works with methods that have one loop. Methods with nested loops don't seem to register the reload hotkey.

Someone said I was missing the point of the reload key, but I don't know enough about AHK to find an alternative that let's me "restart."

Code: Select all

#Requires AutoHotkey v1.1.33
#Persistent

;==============================================================================

; Controls


Hotkey	!Q, party_clicking		; Pressing alt + q will start function
; Presses the left mouse click button 350 times, then waits a few seconds for the page to reload. Repeats 20 times.

Hotkey	!W, misc_clicking       	; Pressing alt + w will start function
; Simply presses the left mouse click button 2,000 times.

Hotkey	!1, 1_click      ; Pressing alt + 1 will start function
; Clicks the 1 key 45 times, then presses next. Repeats 251 times.

Hotkey	!2, 2_click      ; Pressing alt + 2 will start function
; Clicks the 2 key 45 times, then presses next. Repeats 251 times.

Hotkey	!3, 3_click        ; Pressing alt + 3 will start function
; Clicks the 3 key 45 times, then presses next. Repeats 251 times.

Hotkey	!4, 4_click     ; Pressing alt + 4 will start function
; Clicks the 4 key 45 times, then presses next. Repeats 251 times.

Hotkey	!5, 5_click     ; Pressing alt + 5 will start function
; Clicks the 5 key 45 times, then presses next. Repeats 251 times.

^Esc::ExitApp	; Pressing ctrl + esc will close the AHK script
^1::Pause		; Pressing ctrl + 1 will pause/play the script
^2::Reload		; Pressing ctrl + 2 will reload the script
^3::Edit		; Pressing ctrl + 3 will open the script in notepad

;==============================================================================

party_clicking:
{

	Loop, 20 {
		Loop, 350 {
		
			Sleep 120
			MouseClick, left

		}
	
		Sleep 8000
	}

	return
}

;==============================================================================

misc_clicking:
{

	Loop, 2000 {
		
		Sleep 120
		MouseClick, left

	}

	return
}

;==============================================================================


sour_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {1 55}
		Send {d 1}

	}

	return
}

;==============================================================================


2_click:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {2 55}
		Send {d 1}

	}

	return
}

;==============================================================================


3_click:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {3 55}
		Send {d 1}

	}

	return
}

;==============================================================================


sweet_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {4 55}
		Send {d 1}

	}

	return
}

;======================================


5_click:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {5 55}
		Send {d 1}

	}

	return
}

User avatar
mikeyww
Posts: 26928
Joined: 09 Sep 2014, 18:38

Re: Reload Issues

Post by mikeyww » 27 May 2023, 10:21

I recommend posting a script that the forum reader can run to demonstrate the problem that you are experiencing.

MonkeyMode
Posts: 10
Joined: 14 Feb 2021, 10:42

Re: Reload Issues

Post by MonkeyMode » 28 May 2023, 16:59

mikeyww wrote:
27 May 2023, 10:21
I recommend posting a script that the forum reader can run to demonstrate the problem that you are experiencing.
Apologies, I had tried to replace my hotkey names and I didn't check to see if it all still worked and had replaced what I thought I replaced. Giving up on name changes as that messed me up somewhere...

This script runs/works for me and is testable.

Code: Select all

#Requires AutoHotkey v1.1.33
#Persistent

;==============================================================================

; Controls


Hotkey	!Q, party_clicking		; Pressing alt + q will start function
; Presses the left mouse click button 350 times, then waits a few seconds for the party page to reload. Repeats 20 times.

Hotkey	!W, misc_clicking       	; Pressing alt + w will start function
; Simply presses the left mouse click button 2,000 times. Idea for large clicklists.

Hotkey	!1, sour_field_clicking       ; Pressing alt + 1 will start function
; Clicks the 1 key (feed sour berry) 45 times, then presses next. Repeats 251 times.

Hotkey	!2, spicy_field_clicking      ; Pressing alt + 2 will start function
; Clicks the 2 key (feed spicy berry) 45 times, then presses next. Repeats 251 times.

Hotkey	!3, dry_field_clicking        ; Pressing alt + 3 will start function
; Clicks the 3 key (feed dry berry) 45 times, then presses next. Repeats 251 times.

Hotkey	!4, sweet_field_clicking      ; Pressing alt + 4 will start function
; Clicks the 4 key (feed sweet berry) 45 times, then presses next. Repeats 251 times.

Hotkey	!5, bitter_field_clicking     ; Pressing alt + 5 will start function
; Clicks the 5 key (feed bitter berry) 45 times, then presses next. Repeats 251 times.

^Esc::ExitApp	; Pressing ctrl + esc will close the AHK script
^1::Pause		; Pressing ctrl + 1 will pause/play the script
^2::Reload		; Pressing ctrl + 2 will reload the script
^3::Edit		; Pressing ctrl + 3 will open the script in notepad

;==============================================================================

party_clicking:
{

	Loop, 20 {
		Loop, 350 {
		
			Sleep 120
			MouseClick, left

		}
	
		Sleep 8000
	}

	return
}

;==============================================================================

misc_clicking:
{

	Loop, 2000 {
		
		Sleep 120
		MouseClick, left

	}

	return
}

;==============================================================================


sour_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {1 55}
		Send {d 1}

	}

	return
}

;==============================================================================


spicy_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {2 55}
		Send {d 1}

	}

	return
}

;==============================================================================


dry_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {3 55}
		Send {d 1}

	}

	return
}

;==============================================================================


sweet_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {4 55}
		Send {d 1}

	}

	return
}

;======================================


bitter_field_clicking:
{

	SetKeyDelay, 100

	Loop, 251 {

		Send {5 55}
		Send {d 1}

	}

	return
}

User avatar
mikeyww
Posts: 26928
Joined: 09 Sep 2014, 18:38

Re: Reload Issues

Post by mikeyww » 28 May 2023, 17:09

I had no trouble with it. Test in Notepad. Close other scripts. Braces that bound subroutines have no role in v1 and should be removed.

The Hotkey command seems unnecessary for this script. You could just set the hotkeys directly for the subroutines.

MonkeyMode
Posts: 10
Joined: 14 Feb 2021, 10:42

Re: Reload Issues

Post by MonkeyMode » 30 May 2023, 17:47

I am still having issues with using the "pause" Hotkey ctrl + 1 when running a loop-within-a-look, like sour_field_clicking. However, you're right that the ctrl + 2 reload actually does work! I think I had just not given it enough time to test previously, since i have to wait for the loop to end to see the reload take place.

How would you set hotkeys directly for the subroutines? (Also, are subroutines the blocks I've labeled as "misc_clicking" and such?)

User avatar
mikeyww
Posts: 26928
Joined: 09 Sep 2014, 18:38

Re: Reload Issues

Post by mikeyww » 30 May 2023, 19:21

Some ideas are below. When AHK sends a key such as 2, it will ensure that the modifiers are up. If you are sending them down at the same time, a conflict can occur. The #If directive can help in this circumstance as shown. An alternative is simply picking a different hotkey, such as F3.

Code: Select all

#Requires AutoHotkey v1.1.33
SetKeyDelay 100
SoundBeep 1500

#If GetKeyState("Ctrl", "P")
*1::Pause
*2::Reload
#If

!q::
Loop 20 {
 Loop 350 {
  Sleep 120
  Click
 }
 Sleep 8000
}
Return

!w::
Loop 2000 {
 Sleep 120
 Click
}
Return

!1::
!2::
!3::
!4::
!5::
hk := SubStr(A_ThisHotkey, 0)
Loop 251 {
 Loop 55
  Send % hk
 Send d
}
Return
If a hotkey interrupts an executing subroutine, then the interrupted subroutine will resume when the interrupting subroutine ends.

Subroutine

Code: Select all

#Requires AutoHotkey v1.1.33
SetKeyDelay 100
SoundBeep 1500

F3::Pause
!w::clikLoop(2000)
!q::
Loop 20 {
 clikLoop(350)
 Sleep 8000
}
Return

!1::
!2::
!3::
!4::
!5::
hk := SubStr(A_ThisHotkey, 0)
Loop 251 {
 Loop 55
  Send % hk
 Send d
}
Return

clikLoop(n) {
 Loop % n {
  Sleep 120
  Click
 }
}

Post Reply

Return to “Gaming Help (v1)”