how to Start/stop script with hotkey?

Ask gaming related questions (AHK v1.1 and older)
helpcooldo
Posts: 3
Joined: 19 Apr 2021, 14:52

how to Start/stop script with hotkey?

19 Apr 2021, 14:55

I'm just using the script at a VERY basic level. I have it setup already to hit 3 every 2.5 seconds which is perfect for what I'm using it for. The only problem I have is to shut it off or on I have been hitting windows key, right clicking the icon and clicking pause.

PLEASE tell me there's a bettter way to do this?

Current code:

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.

#Persistent
SetTimer, PressTheKey, 2500
Return

PressTheKey:
Send, 3
Return
[Mod edit: [code][/code] tags added.]

Thanks for the help! ♥
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: how to Start/stop script with hotkey?

19 Apr 2021, 15:38

Add a hotkey to toggle the script as paused or not:

Code: Select all

Tab::Pause
helpcooldo
Posts: 3
Joined: 19 Apr 2021, 14:52

Re: how to Start/stop script with hotkey?

19 Apr 2021, 16:30

boiler wrote:
19 Apr 2021, 15:38
Add a hotkey to toggle the script as paused or not:

Code: Select all

Tab::Pause
I put it in my code but it's not working no matter where I place it.
User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: how to Start/stop script with hotkey?

19 Apr 2021, 17:13

So you're saying when you run the script below, when you press the Tab key, the script isn't paused? And when you press it again, it's not resumed?

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.

#Persistent
SetTimer, PressTheKey, 2500
Return

PressTheKey:
Send, 3
Return

Tab::Pause

Make sure you save the script file before running it. And make sure you don't have any other version of the script running that may be sending the 3. Look specifically at the tray icon for this script and see whether or not it turns from green to red (and back) when you press the Tab key, indicating it is paused/un-paused. If you have some other script running that uses the Tab key as a hotkey, then choose a different hotkey for this script.

I'm guessing when you first tried it and it didn't work, it was because you put it at or near the top of the script, before the SetTimer command, which prevented that line from being executed because it was effectively removed from the auto-execute section of the script. Then if it didn't work if/when you moved it somewhere below the SetTimer, you must have had some other issue as I suggested above.
helpcooldo
Posts: 3
Joined: 19 Apr 2021, 14:52

Re: how to Start/stop script with hotkey?

19 Apr 2021, 18:22

boiler wrote:
19 Apr 2021, 17:13
So you're saying when you run the script below, when you press the Tab key, the script isn't paused? And when you press it again, it's not resumed?

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.

#Persistent
SetTimer, PressTheKey, 2500
Return

PressTheKey:
Send, 3
Return

Tab::Pause

Make sure you save the script file before running it. And make sure you don't have any other version of the script running that may be sending the 3. Look specifically at the tray icon for this script and see whether or not it turns from green to red (and back) when you press the Tab key, indicating it is paused/un-paused. If you have some other script running that uses the Tab key as a hotkey, then choose a different hotkey for this script.

I'm guessing when you first tried it and it didn't work, it was because you put it at or near the top of the script, before the SetTimer command, which prevented that line from being executed because it was effectively removed from the auto-execute section of the script. Then if it didn't work if/when you moved it somewhere below the SetTimer, you must have had some other issue as I suggested above.
Huh, not sure why it didn't work before. I placed it above #persistent, below it, in between Return and PressTheKey, and at the bottom like you did... welp I havent a clue why it didn’t work (prob runnign wrong version like you said) either way it's working now, Thank you! ^^

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 73 guests