Is it possible to make emacs interpet an fn key as a modifier key? Can I bind f6, f.ex. to hyper?
I had this:
(setq ns-function-modifier 'hyper) ; set Mac's Fn key to type Hype
And tried to do this:
(setq <f6> 'hyper)
But the latter did not work.
I'd prefer not making the OS as a whole see f9 as some sort of modifier key (making it possible to more easily use the function keys for different purposes in other apps).
Edit: It seems like one possible solution is to bind f9
to C-x @ h
but when I try to get the documentation for the function C-x @
or C-x @ h
I don't get any result. (It only shows a documentation for the function if I actually do a command and then notes that h-x
was "translated" from C-x @ h x
. So if there's some way to bind C-x @ h
to a key via a function (I guess a macro could work, but I prefer using elisp when possible) I suppose that would solve my problem.
http://www.gnu.org/software/emacs/manual/html_node/emacs/Modifier-Keys.html
Even if your keyboard lacks these additional modifier keys, you can enter it using C-x @: C-x @ h adds the “hyper” flag to the next character, C-x @ s adds the “super” flag, and C-x @ a adds the “alt” flag. For instance, C-x @ h C-a is a way to enter Hyper-Control-a. (Unfortunately, there is no way to add two modifiers by using C-x @ twice for the same character, because the first one goes to work on the C-x.)
If you want it to act as a hyper modifier in the sense that you hold it down in conjunction with the key being modified, then no -- that's an OS-level thing, so you would need to take care of it outside of Emacs. xmodmap
is the standard approach under Unix, and if memory serves I've read that it works in OSX.
You can absolutely bind the function called by C-x @ h
(event-apply-hyper-modifier
) to another key sequence, however.
The reason you had trouble determining that function name was that the binding is in one of the so-called "translation keymaps" which "specify translations to make while reading key sequences, rather than bindings for complete key sequences." Hence C-hk (which reads a key sequence) can't be used to establish that. OTOH note that you can still use C-x@C-h to see everything with the C-x@ prefix, which does give you the information you were after.
For more details, see C-hig (elisp) Translation Keymaps
RET
In general, the event-apply-*-modifier
functions (for shift, control, meta (your Alt key), super, hyper, & alt (not your Alt key)) read the next key from the user, and then apply the required modifier to that key, passing the result through as if it had been typed using the real modifier key.
The following (which I've lifted from another answer of mine) would use the number keys on the keypad to represent all the modifier keys.
You could then type the sequence h-x as <kp-5>x
(define-key function-key-map (kbd "<kp-1>") 'event-apply-control-modifier)
(define-key function-key-map (kbd "<kp-2>") 'event-apply-meta-modifier)
(define-key function-key-map (kbd "<kp-3>") 'event-apply-super-modifier)
(define-key function-key-map (kbd "<kp-4>") 'event-apply-shift-modifier)
(define-key function-key-map (kbd "<kp-5>") 'event-apply-hyper-modifier)
(define-key function-key-map (kbd "<kp-6>") 'event-apply-alt-modifier)
n.b. For F9 use (kbd "<f9>")
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With