Error: Invalid key name Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Grendahl
Posts: 170
Joined: 30 Sep 2013, 08:21

Error: Invalid key name

Post by Grendahl » 27 Jan 2023, 14:37

I'm getting the error:
Error: Invalid key name.
Text: keydown
The program will exit.

from the code below.
It was fine in 1.1L, but I'm having issues converting these two to v2.

Anyone have any suggestions?

Code: Select all

Loop {
	for sendkey, value in keys { ; Loop through each of the keys in key_list
		if (value){
			Send("{blind} {" . sendkey . " down}")
			Send("{blind} {" . sendkey . " up}")
		}
	}
	NewDelay := rnd(delay*.9,delay*1.1)
	Sleep NewDelay
}


keydown( ; Keys are pressed
	key := SubStr(A_ThisHotkey,3)
	keys[key] := 1
)


keyup( ; Keys are released
	key := SubStr(A_ThisHotkey,3)
	key := substr(key, 1, StrLen(key) - 3)
	keys[key] := 0
)

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Error: Invalid key name

Post by swagfag » 27 Jan 2023, 14:55

post the v1 code

User avatar
Grendahl
Posts: 170
Joined: 30 Sep 2013, 08:21

Re: Error: Invalid key name

Post by Grendahl » 27 Jan 2023, 14:57

Code: Select all

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

Loop { 
	for sendkey, value in keys { ; Loop through each of the keys in key_list
		if (value){
			Send, {blind}{%sendkey% down}
			Send, {blind}{%sendkey% up}
		}
	}
	;Sleep %Delay%
	NewDelay := rnd(delay*.9,delay*1.1)
	Sleep %NewDelay%
}
return ;End of autoexecute section

; Keys are pressed
keydown:
	key := SubStr(A_ThisHotkey,3)
	keys[key] := 1
return

; Keys are released
keyup:
	key := SubStr(A_ThisHotkey,3)
	key := substr(key, 1, StrLen(key) - 3)
	keys[key] := 0
return

keylist is an array containing the keys... 1,2,3,etc.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Error: Invalid key name  Topic is solved

Post by swagfag » 27 Jan 2023, 15:24

Code: Select all

key_list := ['1', '2', '3']
keys := Map() ;Build lookup array, declare hotkeys
for key in key_list
{
	keys[key] := 0 ; init array values
	hotkey('$*' key, keydown, 'On') ; Declare hotkeys for up and down events
	hotkey('$*' key ' up', keyup, 'On')
}

Loop { 
	for sendkey, value in keys { ; Loop through each of the keys in key_list
		if (value){
			Send('{blind}{' sendkey ' down}')
			Send('{blind}{' sendkey ' up}')
		}
	}
	;Sleep %Delay%
	NewDelay := rnd(delay*.9,delay*1.1)
	Sleep NewDelay
}

; Keys are pressed
keydown(ThisHotkey) {
	key := SubStr(A_ThisHotkey,3)
	keys[key] := 1
}

; Keys are released
keyup(ThisHotkey) {
	key := SubStr(A_ThisHotkey,3, -3)
	keys[key] := 0
}

User avatar
Grendahl
Posts: 170
Joined: 30 Sep 2013, 08:21

Re: Error: Invalid key name

Post by Grendahl » 27 Jan 2023, 15:30

Thanks, that was it! I see what I was doing wrong there too. :)

Post Reply

Return to “Ask for Help (v2)”