I want to change keyboard layout in Linux by programming, What X11's API function does this?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- how to get running process information in java?
A pure X11 API solution should look something like this:
Compile with
-lX11
flagThis will print something like
pc+us+inet(evdev)
for English (USA) qwerty layout,pc+ru+us:2+inet(evdev)
for Russian йцукен layout,pc+us(dvorak)+us:2+inet(evdev)
for English dvorak layout.I'm not sure what the X11 library function is but setxkbmap is the bash command I use to achieve it. Maybe searching along these lines will find what you want (or at a pinch you could just execute the bash command).
Example
EDIT: After a strace of setxkbmap didn't turn up anything useful I suggest just calling:
I found one good solution. It's a c++ class wrriten by Jay Bromley, that I can add to my app and using it.
source code
It's very easy to use:
you can read source code and found some another useful functions. for compiling standalone version you need to un-comments "int main" function present in "XKeyboard.cpp" (or write your own main.cpp) and use somethings like this:
Yesterday I was trying to make auto layuout switcher to EN for Google's xsecurelock. I tryed to find some existing solutions for X11 api, but...
So I decided to write my own with some help from S. Razi. Here is the code: (run with gcc -lX11)
Here you can change char* temp = "English" to name of the group of your layout (exmp: "Russian"), and this simple code will switch your current layout :)