0

I'm using vanilla emacs and since I'm using a nonstandard keyboard layout, I've used dual-function-keys to modify the left alt key so it sends left alt if it is tapped and right alt if it is held. I would like emacs to interpret the sent tapped left alt as a command to apply the meta modifier to the next key pressed. The wiki is unclear on whether this is possible [1]. My naive attempts of

  (define-key key-translation-map (kbd "<lmeta>") 'event-apply-alt-modifier)

and

  (define-key key-translation-map (kbd "<lalt>") 'event-apply-alt-modifier)

didn't seem to work. Is there a way to do this?


  [1]: https://www.emacswiki.org/emacs/StickyModifiers

1 Answer 1

1

Emacs doesn't process modifiers on their own. It needs a non-modifier key (the key which is being modified) to be involved in order to register a key sequence / binding. So no, I don't believe it's possible to do what you're attempting.

I suppose you could tell your keyboard to make "tapping alt" send a non-modifier event and then tell Emacs to bind that to event-apply-alt-modifier but that's not going to be very helpful for other applications.

To be honest, though, I don't understand what you've done... if you've already configured your keyboard or OS so that tapping alt modifies the next key, why do you need to tell Emacs anything at all? Is it not then receiving the modified key?

(E.g. I use sticky modifier keys, and it's purely an OS-level thing -- Emacs neither knows nor cares that I'm doing that.)

4
  • Interesting. I was hesitant to implement sticky keys on the OS-level if there was a way to do so in Emacs. Currently, if I tap Alt, it only sends alt, it doesn't modify the next key. Do you use Linux? If so, how do implement sticky keys? Commented Mar 9, 2023 at 11:42
  • Can Emacs recognize right control key? As far as I know, VirtualBox can do that, so I wonder whether Emacs can, too. (vbox recognizes a single right control key to help user get out from the virtual machine.) If Emacs can recognize a single right control key, it is possible to make right control key sticky at least.
    – shynur
    Commented Mar 9, 2023 at 12:09
  • All modifiers are treated the same way -- Emacs doesn't react to any of them unless they are accompanied by a non-modifier key.
    – phils
    Commented Mar 9, 2023 at 13:51
  • In GNU/Linux I'm using xkbset sticky latchlock -twokey -accessx ("Turn on stickykeys. Turn on "latch lock" (i.e. pressing a modifier key twice "locks" it on). Don't allow two keys pressed at the same time to disable sticky keys. Don't let pressing SHIFT 5 times disable sticky keys.") and xkbset exp 64 =sticky =latchlock =twokey =accessx ("Disable expiration of "sticky keys" after the specified time in seconds. (When expiration is enabled, sticky keys are permanently disabled after that many seconds. This is quite unhelpful.)")
    – phils
    Commented Mar 9, 2023 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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