Remapping Ctrl Key for Copilot in Linux

Making Copilot Keywork Right: Remapping Ctrl Key in Modern Linux

Abstract: Learn how to remap the Ctrl key to work with Copilot in modern Linux distributions like Gnome and Wayland.

by

Making Copilot Key Work Right: Remapping the Ctrl Key in Modern Linux (Gnome/Wayland)

The latest laptops are coming with new features, such as replacing the normal right Ctrl key with a Copilot key. This key does not send the usual one or two escape codes but instead sends a left Ctrl code. If you are using a modern Linux distribution with Gnome and Wayland, you might wonder how to remap this Copilot key to behave like a regular Ctrl key.

Identifying the Copilot Key

The first step is to identify the Copilot key. You can do this by running the following command:

xev

Once you run this command, a new window will appear. Click on the Copilot key, and you will see output similar to the following:

KeyRelease event, serial 37, synthetic NO, window 0x3400001,
root 0x1d9, subw 0x0, time 1015557, (435,313), root:(1236,546),
state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

As you can see, the keycode is 37, which is the left Ctrl key. However, the keysym is Control_L, which indicates that this is the left Ctrl key. In our case, we need to remap the right Ctrl key to behave like the left Ctrl key.

Remapping the Copilot Key

To remap the Copilot key, we need to create a custom keyboard layout. We can do this using the xkb tool. First, create a new file called copilot in the /usr/share/X11/xkb/symbols directory:

sudo nano /usr/share/X11/xkb/symbols/copilot

Add the following content to the file:

partial alphanumeric_keys
xkb_symbols "copilot" {

    include "us(basic)"

    key  { [ Control_L ] };

};

This will remap the right Ctrl key to behave like the left Ctrl key. Save and close the file.

Next, we need to create a new rules file. Create a new file called copilot in the /usr/share/X11/xkb/rules directory:

sudo nano /usr/share/X11/xkb/rules/copilot

Add the following content to the file:

! option
    copilot:switch = +symbols(copilot/copilot)

Save and close the file.

Finally, we need to update the XKB database. Run the following command:

sudo dpkg-reconfigure xkb-data

Select the copilot rules file and save the changes.

Testing the New Keyboard Layout

To test the new keyboard layout, log out and log back in. Open a terminal and run the following command:

setxkbmap -layout us -variant copilot

This will enable the new keyboard layout. Test the Copilot key by running the following command:

xev

Click on the Copilot key, and you should see output similar to the following:

KeyRelease event, serial 37, synthetic NO, window 0x3400001,
root 0x1d9, subw 0x0, time 1015557, (435,313), root:(1236,546),
state 0x10, keycode 64 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False

As you can see, the keycode is now 64, which is the right Ctrl key, but the keysym is still Control_L, which indicates that this key now behaves like the left Ctrl key.

  • Identify the Copilot key by running the xev command and clicking on the key.
  • Create a custom keyboard layout using the xkb tool.
  • Update the XKB database.
  • Test the new keyboard layout by running the setxkbmap command and testing the Copilot key using the xev command.

References

Latest news