6

I often use the M-x command. Is it possible to bind it to my right shift (just the right shift, because I like my left shift the way it is)?


Alright, big thanks to the chosen answer. I solved the problem this way:

# Issued whenever the keyboard layout is changed.
xmodmap -e "keycode 62 = F13"

Then, in my Emacs config, I bind #'smex to <f13>. If you use the standard #'execute-extended-command, use the first (commented) line.

;; (global-set-key (kbd "<f13>") (function execute-extended-command))
(global-set-key (kbd "<f13>") (function smex))
  • 4
    No, it is not possible, at least purely within Emacs. The modifier keys (like shift) have to modify something before Emacs actually sees the keys. As an alternative, you can change the shift key to something else at the OS level (xmodmap for Linux, karabiner for OSX, etc.) and then map that key. – Dan Apr 27 '16 at 13:42
  • 1
    I generalized the title a bit as this seems like a potentially common question. Feel free to change if you disagree. – glucas Apr 27 '16 at 13:52
  • 1
    @Dan: Please consider posting that as an answer. – Drew Apr 27 '16 at 14:12
7

No, it is not possible, at least purely within Emacs.

The modifier keys (like shift) have to modify something before Emacs actually sees the keys. As an alternative, you can change the shift key to something else at the OS level (xmodmap for Linux, karabiner for OSX, etc.) and then map that key to the desired command.

For example: at the OS level, you could map your key to something that Emacs knows about but does not actually exist on your keyboard (say, f20), and then bind f20 to your command within Emacs. The downside, of course, is that every program you use, not just Emacs, sees your key as f20.

  • It should be noted that Emacs can see the modifier key. E.g. here's a way for Qt library, i.e. it's possible in general. The problem rather that elisp doesn't provide any way to bind anything to it. Someone has to report a feature request on that. – Hi-Angel Oct 23 '18 at 10:33
2

My Windows-Menu key runs execute-extended-command (as M-x does).
It's very close to the Shift key. It can be changed too...

(global-set-key (kbd "<menu>") 'find-file)

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.