Using scancodes prevents from using normal key names

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Destiny
Posts: 5
Joined: 21 Nov 2021, 20:04

Using scancodes prevents from using normal key names

Post by Destiny » 21 Nov 2021, 20:13

I need to create a hotkey that works regardless of the keyboard layout. So I tried using the scan codes. However using the same key anywhere else with the ordinary names stops from functioning. For example,

Code: Select all

F12 & SC021::MsgBox, Hello ;This works
F11 & f::MsgBo, World! ;This does not work and outputs 'f'
Using the GetKeyState function doesn't work too. The only way to make it work is to use the scancode for the letter 'f' from now on in the script.

Is there a solution for this to continue using key names instead of scancodes?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Using scancodes prevents from using normal key names

Post by amateur+ » 21 Nov 2021, 23:14

Do you remember that only the first hotkey assignment counts?
F11 and F12 are just prefixes, so you have used the same hotkey (f) twice.
You should fail if you replace SC021 with f also.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Using scancodes prevents from using normal key names

Post by mikeyww » 21 Nov 2021, 23:29

I don't believe that is the case-- and it's easy to prove with your simple test (now disproven).

My impression is that the scan code will "take over" once it is defined-- as described in the original post. I am not aware of a way around it, but also uncertain what problem or use case is being addressed through the script that cannot be handled by using the scan code alone; I do not have an example. Others may have some better explanations & workarounds.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Using scancodes prevents from using normal key names

Post by amateur+ » 22 Nov 2021, 00:04

Oh, yes, I'm a donkey.
And silly thing as f::sc021 doesn't work either, does it? (Not in front of PC now).
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Destiny
Posts: 5
Joined: 21 Nov 2021, 20:04

Re: Using scancodes prevents from using normal key names

Post by Destiny » 22 Nov 2021, 07:50

amateur+ wrote:
21 Nov 2021, 23:14
Do you remember that only the first hotkey assignment counts?
F11 and F12 are just prefixes, so you have used the same hotkey (f) twice.
You should fail if you replace SC021 with f also.
If I don't use the scancode, the 2 hotkeys will work fine.

Destiny
Posts: 5
Joined: 21 Nov 2021, 20:04

Re: Using scancodes prevents from using normal key names

Post by Destiny » 22 Nov 2021, 07:53

mikeyww wrote:
21 Nov 2021, 23:29
I don't believe that is the case-- and it's easy to prove with your simple test (now disproven).

My impression is that the scan code will "take over" once it is defined-- as described in the original post. I am not aware of a way around it, but also uncertain what problem or use case is being addressed through the script that cannot be handled by using the scan code alone; I do not have an example. Others may have some better explanations & workarounds.
Using the keyboard with different keyboard layouts Dvorak and Qwerty. The keys get remapped.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Using scancodes prevents from using normal key names

Post by mikeyww » 22 Nov 2021, 08:17

Does this mean that you cannot use the scan codes throughout your script?

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Using scancodes prevents from using normal key names

Post by amateur+ » 22 Nov 2021, 08:31

I have Colemak (better than DVORAK) and as I can tell, he can use scancodes, but as we know today he has to refuse from using letters after he used its scancode on the primary keyboard layout (QWERTY or DVORAK).
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Destiny
Posts: 5
Joined: 21 Nov 2021, 20:04

Re: Using scancodes prevents from using normal key names

Post by Destiny » 22 Nov 2021, 09:14

mikeyww wrote:
22 Nov 2021, 08:17
Does this mean that you cannot use the scan codes throughout your script?
Well, if I use a scancode once, I'll have to keep using the scancode only for that key. Any further use of letters won't work unfortunately.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Using scancodes prevents from using normal key names

Post by mikeyww » 22 Nov 2021, 09:21

OK. I just want to confirm that if scan codes were used throughout the script, the script would work?

Destiny
Posts: 5
Joined: 21 Nov 2021, 20:04

Re: Using scancodes prevents from using normal key names

Post by Destiny » 22 Nov 2021, 11:57

mikeyww wrote:
22 Nov 2021, 09:21
OK. I just want to confirm that if scan codes were used throughout the script, the script would work?
From what I've tried, if you use the "&" for two key combos, or the "GetKeyState" with a scancode, you'll have to continue using the scancode for that key for those two functions only. the ^!+# combos work like usual with the letters.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Using scancodes prevents from using normal key names

Post by mikeyww » 22 Nov 2021, 12:48

OK. That is what I would do.... not aware of another way. I'll be interested in whether others know of one. Sorry I didn't really help, but I just wanted to know whether the script would work if you made that change.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Using scancodes prevents from using normal key names

Post by amateur+ » 22 Nov 2021, 13:54

Btw, gentlemen, if we put F12 & SC021:: and F11 & f:: into different .ahk files and run them, the problem dissappeares.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: Using scancodes prevents from using normal key names

Post by mikeyww » 22 Nov 2021, 14:51

As expected.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: Using scancodes prevents from using normal key names

Post by amateur+ » 24 Nov 2021, 02:57

@Destiny, what is about GetKeyState() on different keyboard layouts (QWERTY, DVORAK), does it work like we expect? I have a strange output in this test:

Code: Select all

; It is F and J on Qwerty layout
sc21::
sc24::
ToolTip, % GetKeyState("sc21", "P") "`n" GetKeyState("sc24", "P") "`n" GetKeyState(A_ThisHotkey, "P")
return
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Using scancodes prevents from using normal key names

Post by lexikos » 26 Nov 2021, 22:30

Neither AutoHotkey nor the OS tracks key state by scan code, which is why the documentation for GetKeyState says that you can specify "an explicit virtual key code such as vkFF" but does not say the same about scan codes.

What GetKeyState does is convert the KeyName parameter to a virtual key code according to the script's current keyboard layout, then return the state of that virtual key.

(The issue with custom combos is a limitation/bug.)

Post Reply

Return to “Ask for Help (v1)”