Problem when mapping special keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
3be
Posts: 5
Joined: 04 Dec 2022, 17:48

Problem when mapping special keys

Post by 3be » 04 Dec 2022, 19:06

I have a keyboard with several special keys that I am not using for their original purpose and I would like to configure them for something that is more important to me, like Volume Up/Down or Toggle High Contrast Theme.

Here is the 1-st original key history:
A2 01D d 2.88 LControl
A4 038 d 0.00 LAlt
7D 065 d 0.00 F14
A2 01D u 0.19 LControl
A4 038 u 0.00 LAlt
7D 065 u 0.00 F14

So, the first special key is doing the same as LCtrl + LAlt + F14. Here is the code that I am trying to map that key to toggle High Contrast:
<^<!F14::
Send {F14 Up}{LAlt Down}<+{PrintScreen}
Return
<^<!F14 Up::
Send {LAlt Up}
Return

Here is the key history with that code:
A2 01D d 1.70 LControl
A4 038 d 0.00 LAlt
7D 065 h d 0.00 F14
A4 038 i d 0.00 LAlt
A2 01D i u 0.01 LControl
A0 02A i d 0.00 LShift
BC 033 i d 0.00 ,
BC 033 i u 0.00 ,
2C 154 i d 0.02 PrintScreen
2C 154 i u 0.00 PrintScreen
A0 02A i u 0.02 LShift
A2 01D i d 0.00 LControl
A2 01D u 0.14 LControl
A4 038 u 0.00 LAlt
A2 01D i d 0.00 LControl
A2 01D i u 0.00 LControl
7D 065 # u 0.02 F14

It just copies the screenshot of the current window. However, if I press LShift + LAlt + PrintScreen on the keyboard, which is the regular Windows hotkey, I get toggled the High Contrast theme just fine.

Here is the 2-nd original key history:
A4 038 d 6.17 LAlt
7E 066 d 0.00 F15
5B 15B d 0.02 LWin
A4 038 u 0.20 LAlt
7E 066 u 0.00 F15
5B 15B u 0.00 LWin

In this case, the second special key is doing the same as LAlt + LWin + F15. Here is the code that I am trying to map that key to set Volume Up:
#if GetKeyState("LAlt", "P")
LWin & F15::
Send {Volume_Up}
Return

Here is the key history with that code:
A4 038 d 2.33 LAlt
7E 066 d 0.00 F15
5B 15B d 0.01 LWin
A4 038 u 0.17 LAlt
7E 066 u 0.00 F15
5B 15B u 0.02 LWin

As you could see, nothing happens. I tried many other combinations for both keys (e.g. <!<#F15::Volume_Up) without success.

Any help would be greatly appreciated.

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

Re: Problem when mapping special keys

Post by mikeyww » 04 Dec 2022, 19:49

Welcome to this AutoHotkey forum!

Adjusting volume is straightforward: :arrow: SoundSet

The contrast "special key" is, I believe, like Sticky Keys, meaning that this is a special Windows feature that I believe cannot be activated through an AHK Send sequence.

3be
Posts: 5
Joined: 04 Dec 2022, 17:48

Re: Problem when mapping special keys

Post by 3be » 05 Dec 2022, 04:24

Thanks for the reply and for the welcome!

I didn't plan to map any key to Volume Up, I mentioned it just as an example, which was fine for testing purposes since it has a visible result without any side effects like sending a character to the text editor or something like that.

It is more important for me to know why the combination of keys with LWin doesn't work. I could replace Volume_Up with anything else and I still will not get remapped that key.

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

Re: Problem when mapping special keys

Post by mikeyww » 05 Dec 2022, 06:45

A Web & forum search can be helpful in a situation like this. I found a potential solution below.

https://stackoverflow.com/questions/48077438/toggle-highcontrast-theme-windows-10

Also: viewtopic.php?t=41224

3be
Posts: 5
Joined: 04 Dec 2022, 17:48

Re: Problem when mapping special keys

Post by 3be » 11 Dec 2022, 04:46

Thank you so much on this info about toggling the high contrast theme! It works great!

By the way, in meantime I found a solution for the problem with the LAlt + LWin combination with the third key (F15). First of all, this code doesn't work:
#if GetKeyState("LWin", "P")
LAlt & F15::
Send {Volume_Up}
Return

nor this:
#if GetKeyState("LAlt", "P")
LWin & F15::
Send {Volume_Up}
Return

nor this:
#if GetKeyState("LWin", "P") && GetKeyState("LAlt", "P")
*F15::Send {Volume_Up Down}
*<!<#F15 Up::Send {Volume_Up Up}

nor even this:
#if GetKeyState("LWin", "P") && GetKeyState("LAlt", "P")
*F15::Send {Volume_Up Down}
LWin & F15 Up::Send {Volume_Up Up}

However, the next lines work fine:
#if GetKeyState("LAlt", "P") && GetKeyState("F15", "P")
*LWin::Send {Volume_Up}

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

Re: Problem when mapping special keys

Post by mikeyww » 11 Dec 2022, 06:20

Thanks for the report following up the two issues.

The following test did work here.

Code: Select all

<#<!F3::MsgBox, Test

3be
Posts: 5
Joined: 04 Dec 2022, 17:48

Re: Problem when mapping special keys

Post by 3be » 11 Dec 2022, 14:10

Well, it doesn't work for me. It doesn't matter in which order I press the keys, I just get this:

Code: Select all

5B  15B	#	d	4.59	LWin           	
A4  038	 	d	0.00	LAlt           	
72  03D	#	d	0.16	F3             	
72  03D	 	u	0.19	F3             	
5B  15B	 	u	0.11	LWin           	
A4  038	 	u	0.00	LAlt
However, the next lines work fine, but only if I press first LAlt and F3 and just then LWin:

Code: Select all

#if GetKeyState("LAlt", "P") && GetKeyState("F3", "P")
*LWin::MsgBox, Test

Code: Select all

A4  038	 	d	0.51	LAlt           	
72  03D	 	d	0.00	F3             	
5B  15B	h	d	0.27	LWin           	
5B  15B	s	u	0.22	LWin           	AutoHotkey.ahk
72  03D	 	u	0.01	F3             	
A4  038	 	u	0.20	LAlt           	

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

Re: Problem when mapping special keys

Post by mikeyww » 11 Dec 2022, 14:53

OK. Use what works!

Post Reply

Return to “Ask for Help (v1)”