How-to bind Caps Lock to switch keyboard layout in Chrome OS

In a bit hacky way, but it works. Requirements: terminal access (root isn't required).

  1. Open system settings app, go to Keyboard settings -> Caps Lock -> Disabled. Now, this button will return keycode 0;
  2. Enable "Enable shortcut customization app" and "Enable customization in new shortcuts app" in chrome://flags, maybe it will be enabled by default in future versions of Chrome OS, but on 118 it must be enabled, and restart;
  3. Go to Shortcuts app (type "Shortcuts" in search or press Search-Ctrl-S), find "Switch to last language selected" shortcut. Click on pencil at them, and add new shortcut that uses Caps Lock button, for example Search-Ctrl-CapsLock. On screen, instead of CapsLock button you'll see any random button name, eg MailSend;
  4. Close all apps, go to terminal. Now we will modify Preferences file to modify our new hotkey.

In bash shell, create a copy of Preferences file, but in prettified variant.

cd ~
cat Preferences | jq > NewPrefs

Open created NewPrefs file via any text editor, I recommend to use vim or nano , and find our keyboard shortcut, use overrides search keyword. It will look like:

  "accelerator": {
    "overrides": {
      "86": [
        {
          "action": 0,
          "key": 0,
          "key_state": 0,
          "modifiers": 20,
          "state": 0,
          "type": 0
        }
      ]
    }
  },

Only thing that we will change is modifiers - set it to 0 and save file.

Now, we need to apply our NewPrefs file. I used that way, close all other apps because Chrome will be killed. If you can, would be better to perform that from another tty.

mv Preferences Preferences.bak && cp NewPrefs Preferences && pkill -4 chrome

After that, your device will freeze for 5-15 seconds, but you'll be shortly returned into Chrome OS desktop with message that Chrome crashed. Now, open search and press caps lock. All should work.

You can also go to Key Shortcuts app and see that now our added shortcut didn't have any Search/Ctrl/Alt/Shift keys, as we want. Yay.

thumb_up 1 thumb_down 0 chat Comments (0) favorite Donate