Mapping the Z key to a modifier key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
charlie_l
Posts: 2
Joined: 06 Oct 2022, 16:35

Mapping the Z key to a modifier key

Post by charlie_l » 06 Oct 2022, 16:44

Hi,
In my AHK script I want to map the Z key to modifier keys such as ctrl+alt. I want it to work for the duration that I hold down Z, just like modifier keys usually behave.

Using:
z & LButton::^!MButton

Doesn't seem to have the effect that I want, it doesn't seem to hold it down.

What is the proper way to have a letter key as a modifier?

Many thanks.

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

Re: Mapping the Z key to a modifier key

Post by mikeyww » 06 Oct 2022, 20:45

Welcome to this AutoHotkey forum!

Code: Select all

z::
Send {Ctrl down}{Alt down}
KeyWait, z
Send {Alt up}{Ctrl up}
Return

Rohwedder
Posts: 7643
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mapping the Z key to a modifier key

Post by Rohwedder » 07 Oct 2022, 00:57

Hallo,
The docs say:
When a script is launched, each remapping is translated into a pair of hotkeys. For example, a script containing a::b actually contains the following two hotkeys instead:

Code: Select all

*a::
SetKeyDelay -1
Send {Blind}{b DownR}
Return
*a up::
SetKeyDelay -1
Send {Blind}{b Up}
Return
Using the remapping translation to map the Z key to modifier keys such as ctrl+alt
is not possible for two reasons:
1. the two map hotkeys use {Blind}.
2. the first map hotkey holds only a single key DownR.
Your wish: I want it to work for the duration that I hold down Z, just like modifier keys usually behave. is also based on two errors!
1. A user-defined combination of two keys is not triggered by the state of the prefix key (here key Z).
2. Sent modifier keys like in Send, ^!{MButton Down} do not stay pressed.
I suppose what you actually want is:

Code: Select all

z & LButton::SendInput, {Ctrl down}{Alt down}{MButton DownR}
z & LButton Up::SendInput, {Ctrl Up}{Alt Up}{MButton Up}
but it will work only for the duration of holding down LButton.

charlie_l
Posts: 2
Joined: 06 Oct 2022, 16:35

Re: Mapping the Z key to a modifier key

Post by charlie_l » 07 Oct 2022, 03:48

Thanks for all of the help guys, I am getting the result I'm looking for now!

Post Reply

Return to “Ask for Help (v1)”