With AutoHotkey If I press the key Win alone, then nothing happens. That's true except with Emacs, because it opens the Windows menu.

Is there a way to prevent it?

Update: In AHK I have exaclty LWin::Return, but if I press LWin in Emacs the Windows menu opens and checking the AHK Key History I can see

VK  SC  Type    Up/Dn   Elapsed Key     Window
5B  15B     d   9.19    LWin            emacs@ASPC419
5B  15B h   u   0.06    LWin            
5B  15B a   d   0.00    LWin            
5B  15B h   u   0.00    LWin
  • Does emacs even see that key? Does C-h c say anything useful for the <Win> key? On Linux, that key is intercepted by the desktop environment before emacs gets a chance to see it. – NickD Apr 2 '19 at 20:11
  • Try pressing the super key a couple of times a couple of combinations with it (like, pressing it together with letter keys), and then run view-lossage (bound to F1 l by default) to see whether something has registered. Emacs ignores modifier keys by themselves, and windows might be intercepting some keystrokes, which would make your problem related to the operating system and not Emacs itself. – user12563 Apr 2 '19 at 20:47
  • C-h c reports <lwindow> runs the command ignore – Denis Cappellin Apr 3 '19 at 6:49

So firstly, I assume you mean you've set your Windows key to do nothing in AHK with something like: LWin::Return. If this is the case, the Windows menu certainly shouldn't be opening in Emacs.

If you are trying to disable a single keypress of the Windows key in emacs, you should be able to simply set (setq w32-pass-lwindow-to-system nil). I've tested this to work under Windows 10 64bit. Similarily, you can assign the above AHK function to only operate for an Emacs Window.

Alternatively, If you are trying to get the Windows key to act as an additional modifer within Emacs, the answer is less straightforward. In short, it is not possible to get Windows Key to act as super in all contexts through Emacs configuration alone. While you can (setq w32-pass-lwindow-to-system nil) and (setq w32-lwindow-modifier 'super), enabling the functionality for Windows key to act as super — Windows will still intercept any core OS function keystroke (e.g., Win + D to escape to desktop). Thus, you can make Windows key alone not perform anything within Emacs (i.e., not open the menu); and you can assign super commands to any combination which isn't already bound by Windows.

For example, you'll notice that unbound strokes, such as Win + ' will not be intercepted and sent to Emacs. The example snippet below shows that you can assign Win + ] to a command within Emacs.

(setq w32-pass-lwindow-to-system nil
      w32-lwindow-modifier 'super) ;; Menu key

(defun super-test ()
  (message "Super"))

(global-set-key (kbd "s-]") 'super-test)
| improve this answer | |
  • 1
    Adding (setq w32-pass-lwindow-to-system nil) now it works like a charm and in the AHK Key History I cannot see logs about the LWin. – Denis Cappellin Apr 3 '19 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.