How to prevent Alt Key from accessing Window menus?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
piquoramine
Posts: 6
Joined: 30 Nov 2021, 00:15

How to prevent Alt Key from accessing Window menus?

Post by piquoramine » 30 Nov 2021, 00:30

for example when you press alt+space it opens up the system menu
alt+F opens the file menus
alt+E opens the edit menu

Alt+[a random key] gives back a default beep

and so on

i tried Alt::Return but it doesn't seem to affect alt from accessing the system menu in combination with other keys.

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

Re: How to prevent Alt Key from accessing Window menus?

Post by lexikos » 30 Nov 2021, 02:52

You want only the combinations associated with menus to do nothing? Or Alt itself to do nothing in any combination?

If it's the latter, use LAlt::return and/or RAlt::return. Alt:: triggers for either left or right but blocks neither, by design.

piquoramine
Posts: 6
Joined: 30 Nov 2021, 00:15

Re: How to prevent Alt Key from accessing Window menus?

Post by piquoramine » 30 Nov 2021, 04:30

lexikos wrote:
30 Nov 2021, 02:52
You want only the combinations associated with menus to do nothing? Or Alt itself to do nothing in any combination?

If it's the latter, use LAlt::return and/or RAlt::return. Alt:: triggers for either left or right but blocks neither, by design.
I want the system to still detect that I am pressing down alt, just dont want alt to combine with any other button when I'm pressing it

piquoramine
Posts: 6
Joined: 30 Nov 2021, 00:15

Re: How to prevent Alt Key from accessing Window menus?

Post by piquoramine » 30 Nov 2021, 09:27

like if there was a way i could do something along the lines of

LAlt & [Any Key]::Return or something

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

Re: How to prevent Alt Key from accessing Window menus?

Post by lexikos » 01 Dec 2021, 03:13

You can use the Hotkey command in a loop to register many hotkeys.

Alternatively, you can selectively block keys by using InputHook.

Code: Select all

block_alt_hotkeys(activate) {
    static hook := InputHook("L0")
    if activate {
        hook.KeyOpt("{All}", "S")
        hook.Start()
    } else {
        hook.Stop()
    }
}
~*Alt::block_alt_hotkeys(true)
~*Alt up::block_alt_hotkeys(false)
Keys can be excluded by calling hook.KeyOpt(..., "-S") after the first KeyOpt call.

If you press an Alt+something combination, it will act like just Alt. More work is needed if you want to prevent the menu from being focused.

Post Reply

Return to “Ask for Help (v1)”