How can i set Caps Lock to set Russian language and Shift + Caps Lock to set english? Not just Ctrl + Shift to switch them.

  • It's quite possible to set a keyboard shortcut for specific source , but I'd recommend using something else . Caps Lock does let me run custom commands, but still sets all caps. If you would like, i can post an answer, but with different shortcuts . Is that ok ? – Sergiy Kolodyazhnyy Jul 6 '16 at 18:10
  • Hi, Rostislav ! I posted an answer. Please tests it, let me know what you think or if you have any questions. Если нужно обьяснение на русском , дайте мне знать – Sergiy Kolodyazhnyy Jul 6 '16 at 19:01

The python code below is meant to be bound to two different shortcuts. For example for English, bind Ctrl+Alt+1 to

python /path/to/script us

And for Russian, bind Ctrl+Alt+2 to

python /path/to/script ru

For more info on setting shortcuts, read on Luis Alvarado's answer

While in reality setting input source depends on it a sources index in gsettings array, this script determines each source's index automatically and appropriately sets it

Script source code

from gi.repository import Gio
import sys

def gsettings_get(schema,path,key):
    if path is None:
        gsettings = Gio.Settings.new(schema)
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.get_value(key)

def gsettings_set(schema,path,key,value):
    if path is None:
        gsettings = Gio.Settings.new(schema)
        gsettings = Gio.Settings.new_with_path(schema,path)
    return gsettings.set_uint(key,value)

sources = list(gsettings_get('org.gnome.desktop.input-sources', None ,'sources' ))

index = 0
for source in sources:
    for item in source:
        if sys.argv[1] == item:
           index = sources.index(source)

gsettings_set( 'org.gnome.desktop.input-sources' , None, 'current',index )
  • 1
    Nice, but you don't really need a python script, do you? askubuntu.com/q/690539 – Gunnar Hjalmarsson Jul 6 '16 at 21:18
  • 1
    @GunnarHjalmarsson true , one can get away simply with gsettings alone. In fact I posted similar answer today. I'm just making it a bit easy for the user , us on one key, ru on the other. It makes slightly more sense than figuring out which source is which index, and setting lengthy command. Plus it's an exercise in python :) But yes, you're absolutelly right, there's no need for script per se – Sergiy Kolodyazhnyy Jul 6 '16 at 21:23
  • @GunnarHjalmarsson in fact this question is a duplicate, can you please VTC it ? – Sergiy Kolodyazhnyy Jul 6 '16 at 21:28
  • Seems to be closed already. – Gunnar Hjalmarsson Jul 6 '16 at 23:22

As far as I know all you can change is toggling to the next language. You can do it by clicking on the language display on the taskbar and select Text Entry Settings.

There you are presented with two options:

Switch to next source using:
Switch to previous source using:

By changing them you can toggle between languages. If you have only two languages you only need to set the first one (since the second will not add to your functionality).

In your case you can set caps lock as switch to the next source and shift+caps as switch to previous source.

If I may suggest something however it would be to only set switch to next source as shift+caps. That way when typing a document hitting caps lock will not change the language allowing you to easier switch between capital and non-capital characters. Shift+Caps will always change from Russian to English and English to Russian whenever you press it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.