9

Is there a way to use a function key (like <f8>) as a sort of super-key-down event and then have the next keystroke (f.ex. s) then be interpeted as s-s? In other words, this will be similar to sticky modifier keys, but just for emacs, not the os itself.

I know about key-chord mode and the fact that you can use key combinations like this (global-set-key (kbd "<f8> b t") 'undo) to save keyboard shortcuts. But I'd like something that works with my existing bindings to the super key and does not require me to bind everything twice in the future (ie. one binding for the super key and one for the function key).

12

If your workflow is:

  1. Press and release F8
  2. Press and release s, expect it to trigger the binding for s-s
  3. Whatever key you press afterwards does not have the s modifier unless you press F8 again

then this feature exists in Emacs itself. It is bound to C-x @ s by default (clearly only intended for very occasional use). The command is event-apply-super-modifier (similar functions exist for control, shift, meta, alt and hyper). The default bindings are in function-key-map, which is overridden by bindings in the global or local keymaps. You can use key-translation-map instead if you want to the apply-modifier meaning to take precedence.

(define-key function-key-map [f8] 'event-apply-super-modifier)

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.