Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`?

20 Mar 2023, 09:35

Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`?

eg:

Code: Select all

#NoEnv
#SingleInstance Force 
#Persistent

;~ #Include .\Test.ahk
;~ #Include ..\lib\System\RemoveToolTip.ahk 

#IfWinActive, ahk_exe ShareX.exe

~a::
i := 1 ; whatever code not important
return

#IfWinActive

a::
  ;~ displayAhkOutputWindow(A_ThisHotkey)
  ToolTip, % A_ThisHotkey ; >> prints `~a` instead of `a`
return
Press hotkey `a` & See the output \
-- Watch the code: **ToolTip, % A_ThisHotkey ; >> prints `~a` instead of `a`**

Is this a bug?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`?  Topic is solved

20 Mar 2023, 10:23

No bug.

Explained: A_ThisHotkey
When a hotkey is first created -- either by the Hotkey command or a double-colon label in the script -- its key name and the ordering of its modifier symbols becomes the permanent name of that hotkey, shared by all variants of the hotkey.
NorInd
Posts: 43
Joined: 03 May 2020, 04:23

Re: Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`?

21 Mar 2023, 12:16

mikeyww wrote:
20 Mar 2023, 10:23
No bug.

Explained: A_ThisHotkey
When a hotkey is first created -- either by the Hotkey command or a double-colon label in the script -- its key name and the ordering of its modifier symbols becomes the permanent name of that hotkey, shared by all variants of the hotkey.
I see.

So ~a is counted as an variant of a?
So, same for: $a is counted as an variant of a?

I thought only #IfWinActive / #If creates variants.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Why `A_ThisHotkey` is getting the `tilde hotkey` instead of the `normal hotkey`?

21 Mar 2023, 12:19

You can try it and see. Answer the question by running your script.

#IfWinActive creates the variant. Since each hotkey would be triggered by pressing A, I suppose that these two hotkeys are related and paired in terms of names. At least it looks that way through testing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 162 guests