V
V
Vladislav Shepilov2014-02-13 14:39:26
Python
Vladislav Shepilov, 2014-02-13 14:39:26

How to get the current X11 layout?

Help correctly, least "crutch" to get the current X11 layout.
Now this option is used: The skb
utility from a little-known author is installed, respectively, it is not included in any distribution kit. In Python code I use it like this:

import subprocess

keyboard = subprocess.check_output(['skb', '-now']).strip()

There is a binding over Xlib
But there I did not find the implementation of the function, a la "get the current keyboard layout". Interested in a method for obtaining a keyboard layout, in a more acceptable way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kenny_opennix, 2014-02-14
@kenny_opennix

setxkbmap -print and setxkbmap -query

They show the keyboard by default, you can do this with a crutch.
import commands
layout= commands.getoutput("xset -q|grep LED| awk '{ print $10 }' ")
if layout == '00001004':
  print "en"
if layout=='00000000':
  print "ru"

my Russian layout is 00000000, and the English one is 00001004

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question