X11 Keyboard Keyboard Layout XKB – How to Change Currently Selected Keyboard Layout from Command Line

keyboardkeyboard-layoutx11xkb

I have my keyboard layouts (two of them) and switching between them configured via the following command:

setxkbmap -layout us,ru -option -option "grp:lctrl_lshift_toggle,ctrl:nocaps"

Now I want to switch to us layout, using some command line command. Is that possible?

Best Answer

You could use xkb-switch (-n switches to next layout):

xkb-switch -n

or xkblayout-state (with set +1 to wrap around, in your case) :

xkblayout-state set +1

or xte from xautomation to simulate Control_L+Shift_L key press/release:

xte 'keydown Control_L' 'keydown Shift_L' 'keyup Shift_L' 'keyup Control_L'
Related Question