Hotkey from variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Hotkey from variable

22 Feb 2018, 09:43

In the 1st example it is shown working code.

Now I'm trying to create a function from it, but it doesn't work. As I understand, that's because AHK doesn't allow variables as hotkeys?

Code: Select all

/*
; 1st example
f1:: return

^f1::
	hotkey, f1, off
	sendInput, {f1}
	hotkey, f1, on
return
*/

; 2nd example: function
remapHotkey(hotkey) {
	%hotkey%:: return

	^%hotkey%::
		hotkey, %hotkey%, off
		sendInput, {%hotkey%}
		hotkey, %hotkey%, on
	return
}

remapHotkey("f1")
User avatar
boiler
Posts: 16923
Joined: 21 Dec 2014, 02:44

Re: Hotkey from variable  Topic is solved

22 Feb 2018, 11:09

You can't use a variable to define a hotkey using the "::" hotkey defintion. Use the command named Hotkey to define the hotkey.

Also, you shouldn't put the actual hotkey subroutine in the middle of a function.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Anput, dangoscrub, joedf, Nerafius and 129 guests