Auto Hot Key Tutorial

Download: https://autohotkey.com/
right click desktop
select new and find ahk script in the list
open it with a text editor :https://notepad-plus-plus.org/
paste this


#MaxThreadsPerHotkey 3

numpad5::
Toggle := !Toggle
Loop
{
	If (!Toggle)
		Break
	Send 1
	Sleep 83 ; Make this number higher for slower clicks, lower for faster.
}
Return

on the “numpad5” line you can change it with List of Keys (Keyboard, Mouse and Joystick) | AutoHotkey
The “send 1” line is where your spell will fire so in this case it spams the number 1

Good script papapancake1 :slight_smile:

Can you add shift, ctrl and alt keys to this script?

thx in advance

I keep wondering, though, isn’t AHK against the ToS?

Keep wondering… but nope.

That’s great :slight_smile: Been on the fence about it for a long time, but didn’t want to get banned :stuck_out_tongue:

Using it, if you have no other means of repeated key pressing is fine, if you use it for 1 button press = 1 action.

The gray area is where you use 1 button press for multiple actions like pressing 1-2-3 at intervals.
More so when you start scripting AHK to play for you and move your mouse pointers etc to X,Y co-ords etc etc etc.

But for the basic 1 button press it’s absolutely fine.

There are other programs like AHK which do the same job, less hassle etc like Punchkey.
Using a hardware option like mouse/keyboard is better

Very nice, thanks for clarifying :slight_smile:
I’ve never really touched my peripherals’ software ( using a Razer Blackwidow, because GF said it was the best thing ever). Guess I should look into that.

Synapse is easy to set up and would work better for you than AHK.
AHK has other issues too when you spam, like locking up movment etc because it also sends actions to what is called a key queue and will flood it regardless of what you set your delays to.
Add in some movement to this and it’s often ignored and vice versa… becomes frustrating.

Doesn’t happen on hardware options. Not sure if Punchkey has the same issues.
AHK is just mentioned more because it’s popular and people share their scripts :stuck_out_tongue:

Just Download Punchkey, It does Exacty what your looking for…
https://punchkey.weebly.com/

[quote quote=54867]Download: https://autohotkey.com/ right click desktop select new and find ahk script in the list open it with a text editor :https://notepad-plus-plus.org/ paste this

<table class="crayon-table"><tbody><tr class="crayon-row"><td class="crayon-nums " data-settings="show">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
</td><td class="crayon-code">
<span class="crayon-o">#</span><span class="crayon-i">MaxThreadsPerHotkey</span><span class="crayon-h"> </span><span class="crayon-cn">3</span>
<span class="crayon-v">numpad5</span><span class="crayon-o">::</span>
<span class="crayon-v">Toggle</span><span class="crayon-h"> </span><span class="crayon-o">:</span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-o">!</span><span class="crayon-e">Toggle</span>
<span class="crayon-e">Loop</span>
<span class="crayon-sy">{</span>
<span class="crayon-h"> </span><span class="crayon-st">If</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-o">!</span><span class="crayon-v">Toggle</span><span class="crayon-sy">)</span>
<span class="crayon-h"> </span><span class="crayon-st">Break</span>
<span class="crayon-h"> </span><span class="crayon-i">Send</span><span class="crayon-h"> </span><span class="crayon-cn">1</span>
<span class="crayon-h"> </span><span class="crayon-i">Sleep</span><span class="crayon-h"> </span><span class="crayon-cn">83</span><span class="crayon-h"> </span><span class="crayon-sy">;</span><span class="crayon-h"> </span><span class="crayon-e">Make </span><span class="crayon-r">this</span><span class="crayon-h"> </span><span class="crayon-e">number </span><span class="crayon-e">higher </span><span class="crayon-st">for</span><span class="crayon-h"> </span><span class="crayon-e">slower </span><span class="crayon-v">clicks</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-e">lower </span><span class="crayon-st">for</span><span class="crayon-h"> </span><span class="crayon-v">faster</span><span class="crayon-sy">.</span>
<span class="crayon-sy">}</span>
<span class="crayon-st">Return</span>
</td></tr></tbody></table>
on the “numpad5” line you can change it with https://autohotkey.com/docs/KeyList.htm The “send 1” line is where your spell will fire so in this case it spams the number 1 [/quote]

This is a toggle right once u click it u dont need to click it again it will keep repeating… how can i change this exact script but to use key press? Regards

[quote quote=54867]Download: https://autohotkey.com/ right click desktop select new and find ahk script in the list open it with a text editor :https://notepad-plus-plus.org/ paste this

<table class="crayon-table"><tbody><tr class="crayon-row"><td class="crayon-nums " data-settings="show">
1
2
3
4
5
6
7
8
9
10
11
12
13
14
</td><td class="crayon-code">
<span class="crayon-o">#</span><span class="crayon-i">MaxThreadsPerHotkey</span><span class="crayon-h"> </span><span class="crayon-cn">3</span>
<span class="crayon-v">numpad5</span><span class="crayon-o">::</span>
<span class="crayon-v">Toggle</span><span class="crayon-h"> </span><span class="crayon-o">:</span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-o">!</span><span class="crayon-e">Toggle</span>
<span class="crayon-e">Loop</span>
<span class="crayon-sy">{</span>
<span class="crayon-h"> </span><span class="crayon-st">If</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-o">!</span><span class="crayon-v">Toggle</span><span class="crayon-sy">)</span>
<span class="crayon-h"> </span><span class="crayon-st">Break</span>
<span class="crayon-h"> </span><span class="crayon-i">Send</span><span class="crayon-h"> </span><span class="crayon-cn">1</span>
<span class="crayon-h"> </span><span class="crayon-i">Sleep</span><span class="crayon-h"> </span><span class="crayon-cn">83</span><span class="crayon-h"> </span><span class="crayon-sy">;</span><span class="crayon-h"> </span><span class="crayon-e">Make </span><span class="crayon-r">this</span><span class="crayon-h"> </span><span class="crayon-e">number </span><span class="crayon-e">higher </span><span class="crayon-st">for</span><span class="crayon-h"> </span><span class="crayon-e">slower </span><span class="crayon-v">clicks</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-e">lower </span><span class="crayon-st">for</span><span class="crayon-h"> </span><span class="crayon-v">faster</span><span class="crayon-sy">.</span>
<span class="crayon-sy">}</span>
<span class="crayon-st">Return</span>
</td></tr></tbody></table>
on the “numpad5” line you can change it with https://autohotkey.com/docs/KeyList.htm The “send 1” line is where your spell will fire so in this case it spams the number 1[/quote]

This is a toggle right once u click it u dont need to click it again it will keep repeating… how can i change this exact script but to use key press? Regards

this works good but it wont stop lol, i press the button and it just keeps going on its own.

Here is a AHK script I came up with a while back that does exactly what the original poster was looking for. It’s scripted for 2 keys, “1” and “2”, but you only need to modify 2 lines of code to make it work for whichever 2 keys you want it to toggle spamming on and off.
To have the script use keys on the number pad, you would change “1” and “2” to “numpad1” and “numpad2” or whichever 2 keys you wanted to use.

Edited script June 23rd: fixed an issue with Numpad keys not being sent correctly by Sendinput

;   Title: WoWscripts - Spamming macro hotkeys that Toggle themselves ON and OFF
;  author: David J Rosenheim
;    date: July 16, 2016
; purpose: Reposition and resize World of Warcraft window as soon as it's opened
;           then setup multiple hotkeys capable of toggling themselves on and off.

/* ChangeLog
	
	0.9.1.0 Beta   Date: 06/22/20  11:36 PM
	- rewrote script to simplify defining of hotkeys and to make logic a bit more straight forward
	- added logic to detect when special keys are used as hotkeys (i.e. Numpad0 or F1) and to then enclose 
		hotkey name in curly braces "{}" so that SendInput command will send the correct key.
	
	0.9.0.2 Beta   Date: 06/03/20  5:51 PM
	- Fixed issue with hotkey continuing to fire repeatedly while Active window is NOT same window loop started in
	- added a line that can be uncommented to allow testing hotkeys using windows program Notepad.exe
	- added hotkey Ctrl+Alt+R to allow user to quickly Reload this script (needed when chgs made while running)
	- added hotkey Ctrl+Win+X to allow user to Immediately terminate this script and unload it from memory

	0.9.0.1 Beta   Date: 05/15/20  7:09 PM
	- removed WinMaximize and chgd back to WinMove as maximized WoW windows were causing issues when alt-tabbing to other windows
	- script defines 2 winProcesses - 1st for World of Warcraft Retail, 2nd for World of Warcraft Classic
	- created _winGroup and modified script so that hot keys are context-sensitive to only windows in the Group
	
	0.8.0.1  Beta	Date: 9/03/19  1:09:10 PM
	- Changed WinMove to WinMaximize as game window extends beyond left/right side of screen when full height
	
	0.8.0.0  Beta	Date: 9/09/18  3:36:41 PM	
	- Added logic that detects if the current Hotkey is the same as previous hotkey
	- Changed new behaviour that causing currently running spamming loop to switch to a new hotkey character without toggling OFF first.
	- Added _swapHotKeys boolen variable to allow user to turn new "swapping hotkey character" behaviour ON or OFF.
	
	0.7.1.0  Beta	Date: 9/09/18  12:54:14 PM	
	- small number of updates to some comments to make logic more clear
	
	0.7.0.0  Beta	Date: 8/11/16  11:26:26 PM
	- Moved main code to SpamHotKey label so that multiple hotkeys can be processed using the same code
	- changed method of defining hotkeys from double-colon to Hotkey command
	- changed method of specifing context-sensitivity for hotkeys from "#If WinActive(" to "Hotkey, IfWinActive"
	- #MaxThreadsPerHotkey is now 2 instead of 1 and is only defined under the SpamHotKey label
	- Now parsing A_ThisHotkey to get the keystroke for the SendInput command.  Parsing removes "$", if first character.
		Since a hotkey's modifiers (ctrl,alt,shift) are included in its name, parsing A_ThisHotkey ensures that the
		modifiers will be included as part of the keystroke sent by the SendInput command.
	- Suspend hotkey is now working correctly
	- all hotkeys (including Suspend hotkey) are correctly context-sensitive and only working in the _winProcess window. 
*/ 

#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%  ; Ensure a consistent working directory by making script unconditionally use its own folder

_keepFiring := False ; whether to keep spamming hotkey or not
_prevHK     := ""	 ; Previous hotkey (needs to be global so 2nd thread sees what hotkey 1st thread is spamming)
_swapHKs    := True  ; true  = Press same hotkey to toggle OFF; otherwise, switch to new hotkey and keep spamming
					 ; false = Pressing any hotkey toggles OFF current spamming hotkey

_notepad := "ahk_exe notepad.exe"
;GroupAdd, _winGrp, % _notepad             ; uncomment for testing and debugging using Notepad
GroupAdd, _winGrp, ahk_exe Wow.exe        ; add this process to Group
GroupAdd, _winGrp, ahk_exe WowClassic.exe ; add this process to Group

; Only continue after any window in Group becomes Active
WinWaitActive, ahk_group _winGrp
; move and resize the active window
if WinActive(_notepad)
	WinMove, ,, 150, 150, 1000,  650 ; chg x,y,width,height to match preference for Notepad ;
else
	WinMove, ,,  -7,  -9, 1933, 1049 ; chg x,y,width,height to match preference for WoW game client 

#MaxThreadsPerHotkey 2     ; 2 threads are needed so that hotkey loop can be interrupted 
#MaxThreadsBuffer On       ; while loop running, allows 2nd hotkey to be buffered instead of ignored
#IfWinActive, ahk_group _winGrp   ; make following hotkeys context-sensitive (i.e. only work in Group windows)
^!s::Suspend   ; Ctrl+Alt+S - Toggles ON/OFF the Suspend function for all hotkeys
^#x::ExitApp   ; Ctrl+Win+X - Immediately terminate this script and unload it from memory
$1::
$2::
$Numpad5::
Gosub, SpamHotKey  ; rapidfire hotkeys  ("$" in front prevents SendInput cmd from triggering hotkey again)

return

SpamHotKey: 
_thisHK := A_ThisHotkey

If  SubStr(_thisHK,1,1) = "$" 
	_thisHK := SubStr(_thisHK,2)   ; trim "$" char from beginning of hotkey name
if  StrLen(_thisHK) > 1            ; If length of hotkey name is greater than 1, then
	_thisHK := "{" . _thisHK . "}" ;  hotkey is special keyname and must be enclosed in curly braces

; If this is 1st thread, start loop that sends hotkey until toggled OFF
If NOT _keepFiring {  
	_keepFiring := true
	_prevHK := _thisHK
	_thisID := WinActive("A")  ; get Active Window's unique ID nbr (HWND)
	Loop {   ; this loop keeps running until 2nd thread signals to stop spamming any hotkey
		if  NOT WinActive("ahk_id" . _thisID)  ; if NOT same window as when this loop started, then...
			WinWaitActive, ahk_id _thisID      ; pause loop here and wait for original window to become Active again
		sendinput, %_thisHK%    ; send the hotkey pressed
		sleep 59    ; speed of clicks... smaller=faster, larger=slower
		if not _keepFiring   ; If 2nd thread signaled for this loop to stop spamming hotkey, then...
			break   ; Break out of this loop
	}
} 
Else { ; ... this is 2nd thread and 1st thread is already running its loop
	If  (_thisHK = _prevHK or _swapHKs = False) ; if hotkey same as previous hotkey OR no swapping hotkeys, then...
		_keepFiring := false  ; Signal 1st thread to stop looping
	else  ; otherwise, keep loop running and now spam new hotkey
		_prevHK := _thisHK
}

return  ; Ends thread. If this is 2nd thread, 1st thread will resume looping and see any changes made
1 Like

Where would this be posted to please, a bit of a noob with all this

Here are the basic steps:

  1. If you haven’t already, download and install GSE2: Gnome Sequence Enhanced: Advanced Macros https://www.curseforge.com/wow/addons/gse-gnome-sequencer-enhanced-advanced-macros

  2. Startup and log into World of Warcraft, create two custom GSE2 macros for whichever toon, one for single targets, the other for AoE targets, then drag their icons to your WoW action bar. Test your macros by spamming them as fast as you can, the faster the better. Make sure your spells and abilities are firing off in the correct order, firing again when their cool down expires, starting over when you switch targets (if needed), that sort of thing. Edit and tweak your macros until you have them just right.

  3. Download and install AutoHotKey (a.k.a AHK) by going to AutoHotkey Downloads and clicking on the “Download AutoHotKey Installer” button near the top of the page (this assumes you play Wow on a Windows PC). The current version is v1.1.32.00 as of November 24, 2019

  4. After you’ve installed AHK, copy/paste the script above into a blank Notepad, change the hotkeys to match your in-game macro keys, then save the script to your desktop as myWoWscript.ahk or whatever you want to call it, so long as the file extension is “.ahk”.

  5. Launch your new script by simply double clicking its icon on your desktop. You should see a green square icon with a white “H” appear in you system tray. This means the script is running.

  6. Launch World of Warcraft. If you didn’t remove that part of the code, the WoW game client window will automatically resize and reposition itself. If this doesn’t fit your screen size or position the window to your liking, then you can tweak those parts with the help of the AHK spy window which will tell you the position and size of your WoW window after you positioned and sized it to your liking. If you normally run WoW in non-windowed Full Screen mode, then just remove that portion of code from the script.

  7. Log onto the toon you setup your two macros for, find some targets, and test whether your macro keys will now spam themselves by simply being “toggling” On then Off.

Keep in mind, there isn’t any easy way to tell if your macro is firing or not other than the different spells quickly cycling on the action key itself. Pressing one hotkey, then pressing the 2nd hotkey will cause the script to start spamming the 2nd hotkey without stopping first. Pressing the same hotkey twice in a row will cause the script to stop spamming hotkeys. If you happen to open the chat line window while the script is spamming, the current hotkey’s character will start zipping across your chat line. Hit the ESCape key to close the chat line and your actionkey should resume spamming.

2 Likes

Thank you Rosdav,

I will try that later today :slight_smile:
:smile:

Hi Rosdav,
It won’t let me save the file as a AFK, is there a special way to do this please?

Thank you
Tom

Hi Rosdav
I have managed to do it thank you its great :slight_smile:

If you’re using Notepad to copy/paste the script above…
-> in the Menu bar, click on File, then Save As… and the Save As dialog box will appear
-> near the bottom of the dialog box, click on the Save as type: dropdown box and change it from Text documents (*.txt) to All Files (.)
-> in the File name: box just above, enter myWoWscript.ahk or whatever you want to name it, but regardless, you should now be able to save the file with an .ahk extension.