Skip to content

Instantly share code, notes, and snippets.

@BobSynfig
Created June 8, 2019 17:24
Show Gist options
  • Select an option

  • Save BobSynfig/b27e2ed9614a837576658e0a9322b334 to your computer and use it in GitHub Desktop.

Select an option

Save BobSynfig/b27e2ed9614a837576658e0a9322b334 to your computer and use it in GitHub Desktop.
External keyboard with a different layout under Linux
#!/bin/bash
# String identifying the keyboard (under "Virtual core keyboard" with xinput list)
EXT_KEYB_STR="NOVATEK USB Keyboard"
# Taken from Command line
EXT_KEYB_LANG=$1
EXT_KEYB_ID=`xinput list|grep "$EXT_KEYB_STR"|awk -F" " '{print $5}'|awk -F= '{if($2!="") print $2}'|head -n 1`
# This is field #5 because (Word count of EXT_KEYB_STR + 2) --^
setxkbmap -verbose -device $EXT_KEYB_ID -layout $EXT_KEYB_LANG
@BobSynfig

Copy link
Copy Markdown
Author

I use an external keyboard with a different layout (Greek :) ).
Instead of switching all the time the lang from the keyboard shortcut, it can be defined separately.

Usage
ext-keyb gr
ext-keyb us
ext-keyb fr
ext-keyb yourLang

How to install
Download the file and make it executable (chmod +x ./ext-keyb)
Enter xinput list and find your keyboard string under "Virtual core keyboard"
Set it in EXT_KEYB_STR (mine is "NOVATEK USB Keyboard")
The field $5 in EXT_KEYB_ID could be changed if needed.
Move it to /usr/bin to be able to use it system-wide (sudo mv ./ext-keyb /usr/bin)

Hoping that it could be useful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment