1

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

2 Answers2

2

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)
    else:
        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)
    else:
        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

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.

Karsus
  • 961