Q: how can I detect the keyboard layout from Emacs?

I'm writing some code that will set keybindings dynamically by selecting easy-to-reach keys (eg, those on home row). To do this, though, I need to to know which keys correspond to home row on the user's computer.

I could default to assuming that the computer uses the QWERTY layout, but that's not very portable for people using alternate layouts (I, myself, use Dvorak).

How would I detect the keyboard layout? Is there anything portable (in pure elisp) that does it, or would one need to drop to the system level to do it?

(I've browsed through various *-keyboard-* and *-input-method-* variables, and may have missed something obvious.)

PS: there's an old SO thread with a similar title that does not answer this question.

  • 7
    The only portable way of doing this is asking the user to hit a sequence of keys and comparing these against a number of known layouts. In other words, I'm sure you'd need to do platform-specific queries to find out the currently active layout.
    – wasamasa
    Commented Dec 3, 2015 at 17:27


Your Answer

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

Browse other questions tagged or ask your own question.