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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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'
Method 2
Searches of Stack Exchange for kbdmap find this page with no mention of that word. For clarity, here’s an answer (not exactly fitting with the X11 tag of the question, but it should help someone) …
When limited to a virtual console
– without X.
kbdmap(1)
kbdmap,vidfont— front end for syscons and vt… allows easy setting of available keymaps …
Truly, it’s easy and (for me, changing to a UK keyboard layout) effective.
When using X
– for example, with FreeBSD-based TrueOS Desktop.
From post 5 under Change keyboard layout? | The FreeBSD Forums (2015-08-03):
kbdmapis for the console.setxkbmapis the utility you want for X11. …
There’s a warning, for example when changing to United Kingdom:
$ kbdmap kbdcontrol: getting keymap: Inappropriate ioctl for device You are not on a virtual console - expect certain strange side-effects lang_default = en dialect = en_...UTF-8 lang_abk = en … keymap="uk.kbd" $
Method 3
Depending on the distro for the keyboard layouts, the command is
loadkeys <path/to/file> loadkey /lib/kbd/keymaps/i386/qwerty/pt_PT.map.gz
If I remember correctly.
Also check manpage for loadkeys if you want to assign specific keys to specific behavior.
Method 4
Take a look at this howto forge article titled: Changing The Language & Keyboard Layout On Various Distributions, for the various commands to change your keyboard layout on different distros.
Most of these commands present as GUIs but if you look most of them can be run from the command line as well. For example I’m using Fedora (A Red Hat based distro). The command system-config-keyboard when run with no arguments shows me a GUI.
But if I run system-config-keyboard --help it can be run from the command line too:
$ system-config-keyboard --help
Usage: system-config-keyboard [--help] [--noui] [--text] [<keyboardtype>]
--help Print out this message.
--noui Run in command line mode.
--text Run in text interface mode.
<keyboardtype> options are: ar-azerty, ar-azerty-digits, ar-digits, ar-qwerty, ar-qwerty-digits, be-latin1, ben, ben-probhat, bg_bds-utf8, bg_pho-utf8, br-abnt2, cf, croat, cz-lat2, cz-us-qwertz, de, de-latin1, de-latin1-nodeadkeys, dev, dk, dk-latin1, dvorak, es, et, fi, fi-latin1, fr, fr-latin1, fr-latin9, fr-pc, fr_CH, fr_CH-latin1, gr, guj, gur, hu, hu101, ie, is-latin1, it, it-ibm, it2, jp106, ko, la-latin1, mk-utf, nl, no, pl2, pt-latin1, ro, ro-cedilla, ro-std, ro-std-cedilla, ru, sg, sg-latin1, sk-qwerty, slovene, sr-cy, sr-latin, sv-latin1, tj, tml-inscript, tml-uni, trq, ua-utf, uk, us, us-acentos
So to change my keyboard layout to Russian I could run the following command:
$ system-config-keyboard ru
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0