1

The following keys:

  • Ctrl-Win-Left
  • Ctrl-Win-Right

are used to switch desktops on Windows.

If Emacs is the active window when you use either of these keys, you get the following in the minibuffer:

enter image description here

If you're using emacsclient, you may also have the taskbar icon flashing until you switch to that window:

enter image description here

One approach that seems to work to resolve this is adding the following to the init file:

(if (eq system-type 'windows-nt)
    (global-set-key (kbd "<C-lwindow>") 'ignore))

Is that the recommended approach for resolving this?

Is this issue considered a bug for Emacs on Windows? Should the above ignore-behaviour be the default?

1 Answer 1

1

Do you see this if you start Emacs using emacs -Q (no init file)? (I don't.)

If not, bisect your init file to find the culprit.

With emacs -Q on MS Windows 10, Control+Alt+-> (right arrow) is <C-M-right>, and it can be bound or unbound normally. It's bound by default to command forward-sexp.

And with emacs -Q, <C-lwindow> is available and unbound by default.


UPDATED after your edit:

Try putting this in your init file:

(w32-register-hot-key (kbd "<C-lwindow>"))
(w32-register-hot-key (kbd "<C-rwindow>"))

Or maybe something like this (see doc below), to be able to bind only the left window key for Emacs:

(setq w32-lwindow-modifier 'super)
(register-hot-key [s-])

C-h f w32-register-hot-key tells us:

w32-register-hot-key is a built-in function in ‘C source code’.

(w32-register-hot-key KEY)

Register KEY as a hot-key combination.

Certain key combinations like Alt-Tab and Win-R are reserved for system use on Windows, and therefore are normally intercepted by the system. These key combinations can be received by registering them as hot-keys, except for Win-L which always locks the computer.

On Windows 98 and ME, KEY must be a one element key definition in vector form that would be acceptable to define-key (e.g. [A-tab] for Alt-Tab). The meta modifier is interpreted as Alt if w32-alt-is-meta is t, and hyper is always interpreted as the Windows modifier keys. The return value is the hotkey-id if registered, otherwise nil.

On Windows versions since NT, KEY can also be specified as [M-], [s-] or [h-] to indicate that all combinations of that key should be processed by Emacs instead of the operating system. The super and hyper modifiers are interpreted according to the current values of w32-lwindow-modifier and w32-rwindow-modifier. For instance, setting w32-lwindow-modifier to super and then calling (register-hot-key [s-]) grabs all combinations of the left Windows key to Emacs, but leaves the right Windows key free for the operating system keyboard shortcuts. The return value is t if the call affected any key combinations, otherwise nil.

4
  • Hey Drew! Sorry, I meant Ctrl-Win-Left and Ctrl-Win-Right. Yes, I just tried again with emacs -Q and the effect is there. This is on GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-21
    – dharmatech
    Commented Dec 11, 2020 at 16:24
  • Hey Drew! The (w32-register-hot-key (kbd "<C-lwindow>")) approach does not seem to work on my system. I get the same behaviour as before.
    – dharmatech
    Commented Dec 12, 2020 at 21:46
  • Hopefully someone else will have a suggestion that helps.
    – Drew
    Commented Dec 13, 2020 at 3:26
  • Well, the approach I posted in the question is working ok. Just wanted to see if that's the recommended solution and if it's a known issue. Thanks for looking at it!
    – dharmatech
    Commented Dec 13, 2020 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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