Sublime Forum

Disable Alt key tapping open menu in Windows

#1

Hi,

I often mistakenly tap the Alt Key, because I am about to do AltO, but I instead choose to CtrlShiftP The problem is that this opens the menu on the top. Is it possible to disable this? So opening the menu would only be possible through the command palette.

0 Likes

#2

I don’t think there’s any direct way to stop the menu from opening if you just press Alt; I think that’s just something that the OS is more or less doing “for free”, as it were. Sublime won’t let you create a key mapping that’s just a modifier key, for example.

A work-around might be to toggle the menu to hide it completely; when it’s not displayed it won’t get opened when you press Alt. Once it’s hidden the only way to use it is to explicitly toggle it back again using the command in the command palette first.

As work-around’s go, it’s not that great unless you hardly ever touch the menu, though.

1 Like

#3

The only permanent solution I know of is:

repeat this for every plugin that adds its own mnemonics(not all of them do it)

1 Like

#4

How do you hide the menu completely? When I do Toggle Menu from the command palette, I cat still open it with the Alt key.

0 Likes

#5

That’s an interesting solution, but sounds like quite a bit of work. Thanks for the info, though

0 Likes

#6

This happens to me a lot because I’m switching between Mac and Windows machines, where the Super/Alt positions on the keyboards are reversed.

If Sublime had preference setting to completely disable menu bar activation by Alt then I would definitely use it.

2 Likes

#7

Why not remap the keys on one of the machines so it doesn’t happen anymore?

0 Likes

#8

Because a lot of keyboard shortcuts are entirely different, not only in Sublime but throughout the whole OSes. It’s a losing battle to try and normalise it so you don’t have to think.

I’m fine with occasionally using Alt by mistake and having to rethink which command I’m trying to do – I just wish it didn’t wrench me out of the text buffer and into doing something potentially dramatic in the menu bar.

1 Like

#9

No I mean remap the Alt, Ctrl, Super whatever keys so that they appear in the same order as Macs (or reorder the Mac to Windows keys). That’s what I do and I never really have a problem.

0 Likes

#10

They don’t do the same thing though.

Even if the keys are physically lined up [Ctrl] [Super] [Alt] everywhere, a lot of stuff that’s overloaded onto [Ctrl] in Windows/Linux is spread out over both [Ctrl] and [Super] on Mac because Apple made the distinction where more Unix-y shortcuts involve [Ctrl] and more Cocoa-y shortcuts involve [Cmd].

The most obvious example of this being that there’s no conflict between Copying text and sending SIGINT in the Mac terminal because they’re Cmd-C and Ctrl-C respectively.

Also [Alt] on its own has more of a role for typing symbols on Mac. There’s even a band named after this: https://twitter.com/alt_J

I’m rambling a bit here but I’ll just repeat my conclusion that it’s a losing battle to try and normalise the keyboard between platforms.

2 Likes

#11

Well that’s a secondary problem. I’m addressing the “disable alt” issue. I find that most important things correspond, like save or close window and the like, but things then diverge, but they diverge in different applications on the same platform too. There’s nothing much you can do about that besides remap shortcuts across apps you use.

If we’re talking about ST, then I do take issue with how the key bindings are set up for different platforms, and when I have to use Win and Linux more I’ll probably set up a universal set of key bindings across all three platforms which assume certain modifier key remappings.

0 Likes

#12

It’s not that much of work, after you do it on Default\Main.sublime-menu you should regain control of some alt+shortcuts, for the rest, if you find that alt+key opens the menu, it means a plugin has a mnemonic there, look at the menu and find out which plugin, edit the file. You’ll spend much more time looking for (non-existing) alternative solutions, I think.
But if the problem is just for tapping Alt key, this won’t help you actually…

1 Like

#13

Ah, my bad. I was using my Linux machine at the time, and there the menu remains hidden when you press Alt (which is actually a bit irritating because it makes distraction free mode a pain). I see that Windows actually behaves the way I would expect.

1 Like

#14

Well, then I’m switching to Linux. I’ve had enough of Windows anyways…

1 Like

#15

I don’t know if all of the available window managers work the same as the one I’m using, but here pressing Alt doesn’t focus the menu at all. Depending on the distribution you use and/or the window manager it uses and/or settings, other systems may or may not act differently.

That said, anecdotally this post seems to indicate that you could use AutoHotKey to stop this from happening on Windows.

1 Like

#16

AutoHotkey also allows you to restrict the modified behaviour only to the Sublime Text window:

#IfWinActive ahk_exe sublime_text.exe
    ~LAlt Up:: Return
#IfWinActive

I am testing the snippet as I reply and it seems to work fine.

3 Likes

#17

@demetris Oh right, AHK actually always was my solution to everything, I don’t know, why I forgot about it here. Thanks!

0 Likes

#18

LAlt::
sendinput, {LAlt down}
sendinput, {SC0E8 down} ;this is the scan code of an unassigned key. As long as you nor the system never use it for anything else, it can be used in THIS way to cancel the menu acceleration.
;tooltip, Lalt is pressed
KeyWait, LAlt
; That line is important, so that ALT does not continuously fire as you are holding it down.
;tooltip, Lalt was released
return

LAlt up::
sendinput, {LAlt up}
sendinput, {SC0E8 up}
;;;Unlike my 2nd keyboard, this method does not use the scan code as a strict “wrapper.”
;;tooltip,
return

RAlt::
sendinput, {RAlt down}
sendinput, {SC0E8 down}
;;tooltip, Ralt is pressed
KeyWait, RAlt
;;tooltip, Ralt was released
return

RAlt up::
sendinput, {RAlt up}
sendinput, {SC0E8 up}
;;tooltip,
return

0 Likes