AHK help

Can anyone see why my macros isnt firing with mod:alt +1 from the script below?
I dont know AHK much, but been trying to go though the AHK threads here wihtout any luck


#ifWinActive World of Warcraft
Pause::
Suspend
Pause,,1
return

$1::
 While GetKeyState("1","p"){
 Send,,1
 sleep 100
}
return
$+1::
  While ((GetKeyState("Alt","P")) && (GetKeyState("1","p")))
  {  Send +1
     Click
     Sleep 100
  }
  return

$2::
 While GetKeyState("2","p"){
 Send,,2
 sleep 100
}
return

$3::
 While GetKeyState("3","p"){
 Send,,3
 sleep 100
}
return

I know the reply is a little late… but it’s because you never send the modifiers with your Send commands.

Use something like this:


$1:: ;hotkey will fire when 1 is pressed. $ means it won't trigger itself when it sends keys
  While(GetKeyState("1","P")) {
    Send, 1
    Sleep, 100
  }
Return

^$1:: ;hotkey will fire when Alt(!)1 is pressed. $ means it won't trigger itself when it sends keys
	While(GetKeyState("LAlt","P") || GetKeyState("RAlt","P")) {
		Send, {LAlt Down} 1 {LAlt Up}
		Sleep,100
  }
Return

!$1:: ;hotkey will fire when Ctrl(^)1 is pressed. $ means it won't trigger itself when it sends keys
	While(GetKeyState("LCtrl","P") || GetKeyState("RCtrl","P")) {
		Send, {LCtrl Down} 1 {LCtrl Up}
		Sleep, 100
  }
Return

You both have the wrong syntaxes being used for your modifiers.

Unsure where they came from but:

  • = shift
    ! = Alt
    ^ = ctrl

you would also have it set as:

$!1::
Loop
{
if (not GetKeyState(“2”, “P”) and not GetKeyState(“Alt”, “P”))
break
Send !1
sleep 100
}
return

The modifiers were listed at: Hotkeys - Definition & Usage | AutoHotkey

I simply had a typo in the comment text as to which was which.

As far as the hotkey loop… a WHILE loop works great too, just a different way of doing it.

For what it’s worth, here’s what I use. One key press, one action in game. Blizzard has stated that for folks with health issues, repeating that same key is OK.
[edit] removed code, as it’s no longer the current version of what I use. See post below

Thanks for the heads up on the modifiers! :slight_smile: Something I usually don’t get wrong, after working with AHK since it split from AutoIT.

Yeah OK, this re-post looks a lot better :slight_smile:

I was going to comment on the previous one as it still showed syntax errors but this one, while looking like a monster, is much better.

Found a better way to do it last night. Much more elegant code if I say so myself… :slight_smile:

I don’t have it wrapped in a GUI yet, but here’s the script:

;
; AutoHotkey Version: 1.1_L
; Language:       English
; Platform:       Win 64bit
;
; Script Function:
;	Repeatedly presses 0-9 keys while held down, including Alt, Ctrl, and Shift modifiers.
;
#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir% 
SetTitleMatchMode, 2
SetBatchLines, -1

; Set delay between key presses. (too fast will break some games)
Delay := 80

; To add a new key to the script, add it to this array:
key_list := ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ]

; Init lookup array for modifiers
modifiers := {LAlt: 0, LShift: 0, LCtrl: 0}

; only if wow is active
#IfWinActive, World of Warcraft

; Build lookup array, declare hotkeys
keys := {}
keys_modded := {}
Loop % key_list.MaxIndex(){
	key := key_list[A_Index]
	; init array values
	keys[key] := 0
	keys_modded[key] := 0
	; Declare hotkeys for up and down events
	hotkey, $*%key%, keydown
	hotkey, $*%key% up, keyup
}

Loop {
	; Endless loop - always running
	for key, value in keys {
		; Loop through each of the keys
		if (value){
			; If the key is held...
			
			; Detect if any modifiers held
			if (modifiers.LAlt || modifiers.LCtrl || modifiers.LShift){
				modifier_held := 1
			} else {
				modifier_held := 0
			}
			
			; Build the list of modifiers to use for the send
			s := ""
			if (modifiers.LAlt){
				s .= "!"
			}
			if (modifiers.LShift){
				s .= "+"
			}
			if (modifiers.LCtrl){
				s .= "^"
			}
			
			; Send the key with the modifiers
			Send % s "{" key "}"
		}
	}
	Sleep %Delay%
}

; Any of the "keys" (ie not modifiers) being pressed will call this
keydown:
	key := SubStr(A_ThisHotkey,3)
	keys[key] := 1
	return

; Any of the "keys" being released will call this
keyup:
	key := SubStr(A_ThisHotkey,3)
	; Remove " up" from end
	key := substr(key, 1, StrLen(key) - 3)
	keys[key] := 0
	keys_modded[key] := 0
	return

; Modifiers
$*LAlt::
$*LShift::
$*LCtrl::
	mod := substr(A_ThisHotkey, 3)
	modifiers[mod] := 1
	return

$*LAlt up::
$*LCtrl up::
$*LShift up::
	mod := substr(A_ThisHotkey, 3)
	; Remove " up" from end
	mod := substr(mod, 1, StrLen(mod) - 3)
	modifiers[mod] := 0
	return

; Quit script on CTRL-ALT-ESC
!^$Esc::
	ExitApp

Error at line 15

Line text:
Error: This line does not contain a recognized action.

The program will exit.

Can someone point me in the direction I should be going as AHK and macros are confusing. Nor the macros per se as I have that under my belt but the integration both together.

An example say; I have a macro and I put the macro script on the number “1” key but use keybindings to make delete be the number “1” key when pressed, I’ll explain why I use this later. How do I then use an AHK script that I have borrowed for example;
$q::
Loop
{
if not GetKeyState(“q”, “P”)
break
Send q
sleep 100
}
return
$e::
Loop
{
if not GetKeyState(“e”, “P”)
break
Send e
sleep 100
return
}

I know that once the script is running I’m to use “e” or “q” by holding them down to run either Single target macro or AOE macro. The issue I have is since my macro is on the “1” key (single target) and say “2” (bound to “end” from key bindings) for AOE macro, when I hold “e” key down, I strafe right?!?

The reason I use delete, end, PgDn, insert, home, PgUp as keys is due to an arm injury preventing me from stretching out left and I have limited space on the desk. so I move the keyboard to the left and use the arrow keys for movement and the said keys to use spells etc etc

Can anyone help with information or a script that will help in holding down delete or end for single and AOE macro bindings?

Thankyou