I need help

Ask gaming related questions
Monkkey
Posts: 4
Joined: 15 Nov 2023, 05:06

I need help

Post by Monkkey » 15 Nov 2023, 05:18

Hello, I need help with a script for auto clicking generally I need the script to click the letter Z and after a random time in the range of 6 to 10 seconds click the left mouse button wait again a random time in the range of 3 to 5 seconds and click the letter Z again all as a loop enabled by the HOME button and as a script stop END ;x

User avatar
WarlordAkamu67
Posts: 232
Joined: 21 Mar 2023, 06:52

Re: I need help

Post by WarlordAkamu67 » 15 Nov 2023, 13:43

Hello and welcome.

Code: Select all

#Requires AutoHotkey v2.0+
#SingleInstance force

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

End::{
	global toggle := 0
	ToolTip("Off")
	SetTimer () => ToolTip(), -1000
	return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

Home:: {
	global
	toggle := 1
	while (toggle) {
		the_Loop()
}
	return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

the_Loop() {
	Send("z")
	Sleep(Random(6000, 10000))
	Click()
	Sleep(Random(3000, 5000))
	return
}

Monkkey
Posts: 4
Joined: 15 Nov 2023, 05:06

Re: I need help

Post by Monkkey » 16 Nov 2023, 15:17

Almost works only left click doesn't work I tried adding Left to your script in brackets and it doesn't work '=' I don't understand :x

User avatar
WarlordAkamu67
Posts: 232
Joined: 21 Mar 2023, 06:52

Re: I need help

Post by WarlordAkamu67 » 16 Nov 2023, 17:38

If you need to test out some things, you can play around with the Click as needed. Information about it can be found here in the documentation. Below is a screen snippet of the examples of the Click() function
clickexamples.PNG
clickexamples.PNG (44.72 KiB) Viewed 613 times



If you are still unable to get it to work, you can use the Send() function to try and send a {Click}.
sendclickoption.PNG
sendclickoption.PNG (16.41 KiB) Viewed 613 times

Monkkey
Posts: 4
Joined: 15 Nov 2023, 05:06

Re: I need help

Post by Monkkey » 16 Nov 2023, 21:36

I'm a bit new to this environment and previously wrote fairly simple scripts on the first version of autohotkey and they looked like this:

Code: Select all

global break_x = 0
Home::
break_x = 1
Send, {LButton down}
Loop
{
Send, {w down}
Sleep, 300
Send, {w up}
Sleep, 100
Send, {d down}
Sleep, 300
Send, {d up}
Sleep, 100
if( break_x = 2)
{
return
}
}
End::
break_x = 2
Send, {LButton up}
return
and such a script works normally I tried to ask gpt chat what is going on and what it is caused by but it only spit out its own code for me:

Code: Select all

#Persistent ; Keep the script running
SetTimer, TriggerClicks, 6000 ; Run the TriggerClicks function every 6000 ms (6 seconds)
return

~z:: ; ~ signifies that the script does not block the Z key
    TriggerClicks() ; Call the TriggerClicks function
return

~PgDn:: ; Handling the PageDown key
    Toggle := !Toggle ; Toggle the script state (Toggle) to the opposite
    Tooltip, Script % (Toggle ? "enabled" : "disabled") ; Display script status
    Sleep, 2000 ; Wait for 2 seconds to avoid accidental re-enable/disable of the script
    Tooltip ; Hide the tooltip
return

TriggerClicks:
    Random, SleepTime, 6000, 8000 ; Randomly choose a sleep time between 6 and 8 seconds
    Sleep, %SleepTime% ; Wait according to the randomly chosen time
    Click, 6 ; Simulate left mouse button click 6 times
return
In general I have a feeling that the script and more so the mouse click by script is not working in the game just clicking "with" works fine but LMB and a little I don't understand I tried to change to different options you sent in the screenshot but still the same problem


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

Monkkey
Posts: 4
Joined: 15 Nov 2023, 05:06

Re: I need help

Post by Monkkey » 16 Nov 2023, 21:46

I tried now to check in notepad is when you enable the script the cursor completely disappears

User avatar
WarlordAkamu67
Posts: 232
Joined: 21 Mar 2023, 06:52

Re: I need help

Post by WarlordAkamu67 » 17 Nov 2023, 09:02

I was able to reproduce what you are explaining with the disappearing; however, if I move the mouse it reappears. I am still getting Click() to go through. If I move the mouse off the window it clicks out of Notepad.

The first script you posted looks fine, I didn't test it, and its for AutoHotkey Version 1- as you had said. The 2nd script is again written for AHK Version 1, and you would have to debug it yourself as its generated code.

I didn't need to create the extra function and you can use a Loop with (break/continue/whatever you want) instead of a while loop. There are numerous way to go about script it, so maybe others will have an approach you find more suitable. Here is version 2 code that should look/feel more familiar when compared with your V1 script.

Code: Select all

#Requires AutoHotkey v2.0+
#SingleInstance force

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

End::{
	global break_x := 1
	ToolTip("Breaking...") ; Display Notice
	SetTimer () => ToolTip(), -1000 ; Clear the ToolTip after 1 second.
	return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

Home:: {
	global break_x := 0
	Loop {
		if (break_x) {
			break
}
		Send("z")
		Sleep(Random(6000, 10000))
		Click()
		Sleep(Random(3000, 5000))
}
	return
}

; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ; ------------------------- ;

User avatar
DuckingQuack
Posts: 221
Joined: 20 Jan 2023, 18:20

Re: I need help

Post by DuckingQuack » 17 Nov 2023, 22:56

I decided to try to come up with a version that did not use sleeps, but timers instead.
I came up with two ways to go about it, one function that uses variables or two functions that call each other. The single turned out better but I'm going to post both as options for you.

EDIT: Came up with a third one that's infinitely expandable, and it's super compact.


Single Function

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook

Esc::ExitApp
on := False

;;;;;;;;;;;;;;;;;;;;;;;;;
; Single button toggle option (change to preferred key or remove)
F1:: {                  
    Global
    If on := !on
        Next()
}
;;;;;;;;;;;;;;;;;;;;;;;;;
; Requested Home:Start button and End:Stop button
#HotIf !on              
Home:: {
    Global on := True
    Next()
    }
#HotIf
End:: Global on := False
;;;;;;;;;;;;;;;;;;;;;;;;;
; Function that does all the work
Next(){                 
    Static Press := False
    If Press := !Press 
        Key := "z", Period := Random(-6000, -10000)
    else Key := "{Click}", Period := Random(-3000, -5000)
    Send(Key), SetTimer(Next, Period * on)
    If on = False
        Press := False
}


Double Function

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook

Esc::ExitApp

Global on := False
F1:: {
    Global on := !on
    FnZ()
}
Home:: {
    Global on := True
    FnZ()
}
End:: Global on := False

FnZ(){
    Send("z")
    SetTimer(FnClick, Random(-6000, -10000) * on)
} 
FnClick(){
    Click
    SetTimer(FnZ, Random(-3000, -5000) * on)
}


EDIT: Infinitely Expandable

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
InstallMouseHook
InstallKeybdHook
Esc::ExitApp
on := False
F1:: {
    Global on := !on 
    Stuff()
}        
a := ["z", -6000, -10000]
b := ["{Click}", -3000, -5000]
KeyArray := [a,b]
Stuff(){ 
    Global
    Try Key := KeyArray[(Mod(((++X:=on<1?-1:(X??0))-1),KeyArray.Length)+1)]
    Send(Key[1]), SetTimer(Stuff, Random(Key[2], Key[3]) * on)
}
Best of Luck,
The Duck

Post Reply

Return to “Gaming”