Go to the first, previous, next, last section, table of contents.

How do I bind a combination of modifier key and function key?

Unless you're using Emacs under emacstool (or xvetool?), have a working version of x-rebind-key (see section How do I use function keys under X Windows?), or are using Emacs 19 (Lucid Emacs), you can't do this with Emacs alone.

If you are using emacstool, Emacs sees different character sequences for the combination of a modifier and a function key from what it sees for the function key alone. See etc/emacstool.1 for more information. Since Emacs sees different character sequences, you can bind these different sequences to different commands.

If you are running Emacs inside a terminal emulator window like xterm, you can modify its translation tables to make it generate different character sequences for the combination of a modifier and a function key. For example, this X resource setting:

  XTerm.VT100.Translations: #override \
    Shift<KeyPress>F1: string(0x1b) string("[xyzzy")

makes Shift-F1 generate the character sequence "ESC [ xyzzy". You can bind these character sequences in Emacs as normal. Nick Ruprecht <ruprecht@informatik.uni-freiburg.de> has written an extensive X translation mapping for xterm that does this. {Does this have an FTP site?}

If you have x-rebind-key, you can have any arbitrary combination of modifiers with a key replaced by any sequence of "normal" characters. For example, this makes Shift-Return behave as though you had typed "C-x C-e" (example from Jerry Graves):


  (x-rebind-key "Return" 'shift "\C-x\C-e")

In Emacs 19 (Lucid Emacs), you can bind Meta-Left-Arrow like this (example from Jamie Zawinski):


  (global-set-key '(meta left) 'backward-word)

With the last two methods, use `xmodmap' and `xev' to discover the keysym and modifier names.


Go to the first, previous, next, last section, table of contents.