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
up vote 8 down vote accepted

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.

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

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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