Using scan code in hotkey variant fire both hotkeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
axelgauffre
Posts: 6
Joined: 05 Nov 2017, 11:32

Using scan code in hotkey variant fire both hotkeys

13 Dec 2017, 10:56

Hi my friends,

I've been struggling with the probleme below for hours.
I searched the forum and Google but couldn't find any answer to my question.

Watch the following script.
When I use ~*Escape or ~*VK1B (VK1B is the virtual key for the Escape key) for my second hotkey, the script behaves has espected, that is to say, when I press Escape, only the first Msgbox is displayed.
Now, when I use ~*SC001 (SC001 is the scan code for the Escape key) for my second hotkey, strangely , when I press Escape, both the first and second Msgbox are displayed!!

Could anyone tell me why? :-)

Thank you for your time and help.

(I am on Windows 10 with AHK 1.1.23.05)

Code: Select all

#SingleInstance force

Escape::
	MsgBox % 1 A_ThisHotkey
	Return

~*SC001::
;~*Escape::
;~*VK1B::
	MsgBox % 2 A_ThisHotkey
	Return
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Using scan code in hotkey variant fire both hotkeys

13 Dec 2017, 14:31

Based on this link, scan codes (SC) are more hardware dependent. I'm guessing that they simply point to other key names (rather than being replacements for them), so ~*SC001 invokes the key named "Escape"... and because you're using the ~ prefix, your hotkey code for Escape is also being sent, resulting in both message boxes. It seems that VK codes are more a substitute for key names, rather than pointers to them, so they behave more normally and predictably. Of course, you can easily fix this situation by removing the ~ prefix from the SC code, but, if you're looking more for an explanation, that's my guess at what's going on.
axelgauffre
Posts: 6
Joined: 05 Nov 2017, 11:32

Re: Using scan code in hotkey variant fire both hotkeys

13 Dec 2017, 19:10

Thank you anyway for your "guess" Osprey ;-).

However, if anyone has a more precise answer I would still like to hear it. :-)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 311 guests