#MenuMaskKey

AutoHotkey

#MenuMaskKey [AHK_L 38+]

Changes which key is used to mask Win or Alt keyup events.

#MenuMaskKey KeyName

Parameters

KeyName

A key name or vkNN sequence which specifies a non-zero virtual keycode. Scan codes are not used.

Remarks

The default mask key is Ctrl. This directive can be used to change the mask key to a key with fewer side effects.

This setting is global, meaning that it needs to be specified only once (anywhere in the script) to affect the behavior of the entire script.

The mask key is sent automatically to prevent the Start menu or the active window's menu bar from activating at unexpected times.

Hotkeys: If a hotkey is implemented using the keyboard hook or mouse hook, the final keypress may be invisible to the active window and the system. If the system was to detect only a Win or Alt keydown and keyup with no intervening keypress, it would usually activate a menu. To prevent this, the keyboard or mouse hook may automatically send the mask key.

[v1.1.27+]: Pressing a hook hotkey causes the next Alt or Win keyup to be masked if all of the following conditions are met:

  • The hotkey is suppressed (it lacks the tilde modifier).
  • Alt or Win is logically down when the hotkey is pressed.
  • The modifier is physically down or the hotkey requires the modifier to activate. For example, $#a:: in combination with AppsKey::RWin causes masking when AppsKey+A is pressed, but AppsKey on its own is able to open the Start Menu.
  • Alt is not masked if Ctrl was down when the hotkey was pressed, since Ctrl+Alt does not activate the menu bar.
  • Win is not masked if the most recent Win keydown was modified with Ctrl, Shift or Alt, since the Start Menu does not normally activate in those cases. However, key-repeat occurs even for the Win key if it was the last key physically pressed, so it can be hard to predict when the most recent Win keydown was.
  • Either the keyboard hook is not installed (i.e. for a mouse hotkey), or there have been no other (unsuppressed) keydown or keyup events since the last Alt or Win keydown. Note that key-repeat occurs even for modifier keys and even after sending other keys, but only for the last physically pressed key.

Mouse hotkeys may send the mask key immediately if the keyboard hook is not installed.

Hotkeys with the tilde modifier are not intended to block the native function of the key, so in [v1.1.27+] they do not cause masking. Hotkeys like ~#a:: still suppress the menu, since the system detects that the Win key has been used in combination with another key. However, mouse hotkeys and the Win keys themselves (~LWin:: and ~RWin::) do not suppress the Start Menu.

The Start Menu (or the active window's menu bar) can be suppressed by sending any keystroke. The following example disables the ability for LWin to activate the Start Menu, while still allowing its use as a modifier:

~LWin::Send {Blind}{vk07}

Send: Send, ControlSend and related often release modifier keys as part of their normal operation. For example, the hotkey <#a::SendRaw %Address% usually must release the LWin key prior to sending the contents of Address, and press the LWin key back down afterward (so that other Win key combinations continue working). The mask key may be sent in such cases to prevent a Win or Alt keyup from activating a menu.

Related

See this thread for background information.

Examples

#MenuMaskKey vk07  ; vk07 is unassigned.
#UseHook
#Space::
!Space::
    KeyWait LWin
    KeyWait RWin
    KeyWait Alt
    KeyHistory
return