Need help updating a v1 script to v2

Ask gaming related questions
meozzarella
Posts: 4
Joined: 07 Jun 2023, 15:05

Need help updating a v1 script to v2

Post by meozzarella » 07 Jun 2023, 15:16

i've tried my best to re-create this in v2 terms but it just goes over my head.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#MaxThreadsPerHotkey 2
$F12::
	toggle:=!toggle
	While toggle{
	  SendInput {space}
	}
Return

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Need help updating a v1 script to v2

Post by boiler » 07 Jun 2023, 17:01

Code: Select all

#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2

F12:: {
	static toggle := 0
	toggle := !toggle
	while toggle {
		Send "{Space}"
		Sleep 20
	}
}

No $ is needed since you're not sending the same key as the hotkey. The Sleep might be necessary so it doesn't send spaces so quickly that it goes out of control. AHK v2 eliminates the built-in occasional 10 ms pauses that v1 had (what was SetBatchLines -1 in v1 is now default).

meozzarella
Posts: 4
Joined: 07 Jun 2023, 15:05

Re: Need help updating a v1 script to v2

Post by meozzarella » 07 Jun 2023, 17:39

thank you so much; that works perfectly, in everything except for the program i wanted to use it in. google says i may need to use the controlsend command to specify the window/.exe, but again i am lost on how to do so.

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Need help updating a v1 script to v2

Post by boiler » 07 Jun 2023, 19:12

Seems odd that regular Send wouldn't work but ControlSend would, but go ahead and try it. Replace Send "{Space}" with ControlSend "{Space}", "Edit1", "ahk_exe notepad.exe", but put your application's name in place of notepad.exe and the name of the control in place of Edit1. If it doesn't have an addressable control and yo just want to send it to the window, then leave that parameter blank. There's no guarantee it works with all windows, but if you said others have done so, then it should work.

meozzarella
Posts: 4
Joined: 07 Jun 2023, 15:05

Re: Need help updating a v1 script to v2

Post by meozzarella » 07 Jun 2023, 19:27

oh, actually the first script you posted does work for the program i wanted it to (citra emulator) but it only when i hold down the spacebar. in any other window it works automatically without me having to push anything.

meozzarella
Posts: 4
Joined: 07 Jun 2023, 15:05

Re: Need help updating a v1 script to v2

Post by meozzarella » 08 Jun 2023, 18:36

would anyone happen to know how to make the script work without me holding down the spacebar? should this thread be moved into gaming for that?

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Need help updating a v1 script to v2

Post by boiler » 08 Jun 2023, 21:24

It may be that the game checks to see that the spacebar is physically held down to prevent spam scripts like this. Moving to the gaming section since it’s now clear what this is for.

Post Reply

Return to “Gaming”