A
A
Alexander2014-10-02 18:52:12
Keyboard layout
Alexander, 2014-10-02 18:52:12

How to set custom hotkeys for each keyboard layout in Ubuntu?

In the keyboard layout settings in Windows, you can easily set a separate hot key for each keyboard layout. I use Ctr+Shift+1, Ctr+Shift+2 and Ctr+Shift+3. Very used to it.
At work, I have to use Ubuntu, out of habit, every time I need to switch the layout, I reach for this combination. In the Ubuntu settings, I did not find the ability to set my own hot keys for each language. Please tell me how to get out of this situation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-10-03
@xpert13

In general, I made a rather crutch, but quite a working solution. I wrote a script that emulates pressing the layout switching keys the required number of times. For the script to work, you need to install "xkb-switch" (to determine the current keyboard layout) and "xdotool" (to emulate keystrokes). The launch of the script is hung up on pressing the keys you need.
Script code:

#!/bin/bash
source_lang=`xkb-switch`
dest_lang=$1

# Если уже на нужной раскладке
if  
then
  exit 0
fi

# Необходимая задержка (без неё не сработает)
sleep 0.3

# Если 1 раз нужно нажать на переключение раскладки
if  
then
  xdotool key super+space
  exit 0
fi

# Если 2 раза нужно нажать на переключение раскладки
if  
then
  xdotool key super+space super+space
  exit 0
fi

Unfortunately, the script is not universal (I didn’t write bash scripts at all before), because it is tailored for a specific case. In this case, these are:
1. Three languages ​​that go in the order Us, Ru, Ua
2. Layout switching in the system is set to super + space
If someone offers a version of a universal script that will itself determine hotkeys for switching layouts and order languages ​​in the system - I will only be grateful.
The script is launched by the command "<path_to_script> <language_code>", for example, if your file is located in your home directory and has the name "language_switcher.sh", then to switch to Russian, you need to execute "./language_switcher.sh ru" (in fact, such commands and you need to hang on each hot key)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question