Software & AppsOperating SystemLinux

How To Swap Left Ctrl with Left Alt on Keyboard?

Ubuntu 10

In this article, we will delve into the process of swapping the Left Ctrl with the Left Alt on your keyboard. This guide will be particularly useful for those who frequently use keyboard shortcuts and would like to customize their keyboard layout for comfort and efficiency.

Quick Answer

It is possible to swap the Left Ctrl with the Left Alt on your keyboard. There are multiple methods to achieve this, including using .Xmodmap, GNOME Tweaks, or udev. Each method requires a few steps to be followed, but they are relatively straightforward.

Understanding Keycodes and Scancodes

Before we start, it’s important to understand what keycodes and scancodes are. A scancode is a unique identifier that a keyboard sends to a computer to tell it which key was pressed. A keycode is a standard identifier that the operating system uses to interpret what the key press means. In other words, the keyboard sends scancodes, and the operating system translates these into keycodes.

Method 1: Using .Xmodmap

The first method we will discuss involves the use of .Xmodmap, a utility for modifying keymaps and pointer button mappings in Xorg.

Step 1: Creating and Editing the .Xmodmap File

Open your terminal and type the following command:

gedit ~/.Xmodmap

This command will create a new file named .Xmodmap in your home directory and open it in the text editor. If the file already exists, it will simply open it for editing.

Step 2: Adding Key Mapping Instructions

In the .Xmodmap file, add the following lines:

clear control
clear mod1
keycode 37 = Alt_L Meta_L
keycode 64 = Control_L
add control = Control_L Control_R
add mod1 = Alt_L Meta_L

Here’s what each line does:

  • clear control and clear mod1 remove the current control and mod1 (Alt key) mappings.
  • keycode 37 = Alt_L Meta_L and keycode 64 = Control_L swap the left Ctrl and left Alt keys. Keycode 37 usually corresponds to the left Ctrl, and keycode 64 corresponds to the left Alt. These lines tell the system to interpret keycode 37 as left Alt and keycode 64 as left Ctrl.
  • add control = Control_L Control_R and add mod1 = Alt_L Meta_L add the new control and mod1 mappings.

Step 3: Applying the New Key Mappings

Save the .Xmodmap file and quit the text editor. Then, run the following command in the terminal:

xmodmap ~/.Xmodmap

This command applies the new key mappings immediately.

Note: The keycodes used in the example above may be different on your computer. To find the correct keycodes, you can use the xev program. Run xev in the terminal, and a small window will appear. Press the keys you want to swap, and you will see the keycode information in the terminal output. Make sure to update the keycodes in the .Xmodmap file accordingly.

Method 2: Using GNOME Tweaks

If you’re using GNOME as your desktop environment, you can use the GNOME Tweaks tool to swap keys.

Step 1: Installing GNOME Tweaks

Open your terminal and type the following command:

sudo apt-get install gnome-tweaks

This command installs the GNOME Tweaks tool.

Step 2: Swapping Keys

Open GNOME Tweaks and navigate to “Keyboard & Mouse” -> “Additional Layout Options”. Look for the option to swap the Left Alt with Left Ctrl. It may be called “Ctrl position” or something similar. Enable this option.

This method should automatically apply the key swap every time you log in, without the need to run any commands manually.

Method 3: Using udev in Ubuntu 17.10 and Later

If you’re using a newer version of Ubuntu, you can use udev to swap keys.

Step 1: Finding the Scancodes

Open your terminal and type the following command:

sudo evtest

This command will display a list of your input devices. Choose your keyboard from the list, and press the keys you want to swap. The terminal output will display the scancode for each key press.

Step 2: Creating and Editing the udev hwdb file

Next, create a file called 70-keyboard.hwdb in the /etc/udev/hwdb.d/ directory. You can use a text editor to create the file.

In the 70-keyboard.hwdb file, add the following lines to swap the Left Ctrl with Left Alt:

 KEYBOARD_KEY_<hex scan code>=leftalt
 KEYBOARD_KEY_<hex scan code>=leftctrl

Replace <hex scan code> with the actual scan codes you found in step 1.

Step 3: Applying the Changes

Save the file and run the following command:

sudo systemd-hwdb update && sudo udevadm trigger

This command updates the hardware database and triggers the changes.


Swapping keys on your keyboard can greatly enhance your computing experience, especially if you frequently use keyboard shortcuts. Whether you prefer using .Xmodmap, GNOME Tweaks, or udev, the process is relatively straightforward and can be done in a few steps. Happy computing!

Can I swap any keys on my keyboard using these methods?

Yes, you can swap any keys on your keyboard using these methods. However, the specific keycodes or scancodes may vary depending on your keyboard model and operating system.

Will swapping keys affect the functionality of my keyboard?

Swapping keys should not affect the overall functionality of your keyboard. The swapped keys will still perform their intended functions, but their physical positions will be swapped.

Can I revert the key swap if I change my mind?

Yes, you can revert the key swap by following the same methods and instructions, but swapping the keys back to their original positions.

Will these methods work on all operating systems?

These methods are primarily intended for Linux-based operating systems, such as Ubuntu. However, similar concepts and tools may be available for other operating systems, but the specific steps may differ.

Do I need administrator privileges to make these changes?

Yes, for Method 2 (Using GNOME Tweaks) and Method 3 (Using udev), you will need administrator privileges to install GNOME Tweaks and modify system files. Method 1 (Using .Xmodmap) can be performed without administrator privileges.

Will these methods void my warranty or cause any damage to my keyboard?

No, these methods should not void your warranty or cause any damage to your keyboard. They are software-based solutions that modify the key mappings on your computer, not the physical hardware of the keyboard.

Can I use these methods to swap keys on a laptop keyboard?

Yes, you can use these methods to swap keys on a laptop keyboard as well. The steps and instructions remain the same, regardless of whether you are using a desktop or laptop keyboard.

Will the key swap apply to all user accounts on my computer?

Yes, the key swap will apply to all user accounts on your computer. The changes are system-wide and will be effective for all users.

Can I swap keys other than Left Ctrl and Left Alt?

Yes, you can swap keys other than Left Ctrl and Left Alt by modifying the keycodes or scancodes in the respective methods. However, you will need to determine the correct keycodes or scancodes for the keys you want to swap.

Do I need to restart my computer for the key swap to take effect?

No, you do not need to restart your computer for the key swap to take effect. The changes should be applied immediately after following the instructions in each method.

Leave a Comment

Your email address will not be published. Required fields are marked *