Remap keyboard keys using evremap

21 May 2023 | Linux Guide

A close-up view of a purple backlit keyboard with a transparent text overlay reading “evremap”.

Content

  1. Introduction
  2. Building and Installing

    1. Prerequisites
    2. Building
    3. Installing
  3. Usage
  4. Other Options
  5. References

Introduction

Sometimes a key on your keyboard stops working, and you may not have the time or motivation to fix it or get it fixed. Or maybe you just want to change how your keyboard keys work to improve your workflow. All this, and more, can be done with the help of evremap (github.com/wez/evremap).

It is a tool that can remap the keyboard inputs for Linux systems, made by Wez. And because evremap targets the evdev layer of libinput, the remapping is effective system-wide – in Wayland, X11 and the Linux console.

Building and Installing

Prerequisites

Debian and its derivatives like Ubuntu require some prerequisites before we can build it. Use this command to install them:

sudo apt install git cargo pkg-config libevdev-dev

RHEL and its derivates also require some prerequisites. Use the following command to install it:

sudo dnf install git libevdev-devel

Building

First, clone the repository to any folder of your choice. I recommend the Downloads folder, as after building it, you can safely delete it.

cd ~/Downloads && git clone https://github.com/wez/evremap.git && cd evremap

Now, build the binary.

cargo build --release

If everything went fine, the last lines of your terminal output should be something like the ones in the image below.

A screenshot of the terminal after evremap finished building.

Installing

Copy the binary file to the specified location using this command:

sudo cp target/release/evremap /usr/bin/

Now create a config file in the specified location using this command:

sudo touch /etc/evremap.toml

We will edit this file in the Usage section, below.To make your configured remapping active immediately after the system startup we need to create a systemd service. Use the following commands to do so:

sudo cp evremap.service /usr/lib/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable evremap.service
sudo systemctl start evremap.service

Now, you can safely delete the cloned repository.

cd .. && rm -rf evremap

Usage

In the configuration file, we need to state two things, basically – name of the keyboard(s) and name of the keys you wish to remap.

To find the name of all the connected keyboards use the following command:

sudo evremap list-devices

Usually, laptop keyboards will be named “AT Translated Set 2 keyboard”.

To find the name of all the inputs use:

sudo evremap list-keys

The grep command can help you find the keyboards and the keys faster.

For example:

sudo evremap list-devices | grep HOME

Now, let us modify the configuration file. Use the following command to edit it:

sudo nano /etc/evremap.toml

Here is a template that you can copy and paste, and make te changes you need:

device_name = "DEVICE NAME HERE"

[[remap]]
input = ["NAME_OF_THE_KEY_YOU_WILL_PRESS_ON_YOUR_KEYBOARD"]
output = ["NAME_OF_THE_KEY_YOU_NEED_TO_BE_PRESS_AS_THE_OUTPUT"]

[[remap]]
input = ["KEY_COMBINATION_1", "KEY_COMBINATION_2"]
output = ["OUTPUT_KEY"]

[[dual_role]]
input = "KEY_YOU_NEED_TO_CHANGE_THE_RESULT_FOR"
hold = ["KEY_THAT_WILL_BE_PRESSED_WHEN_INPUT_KEY_IS_HELD"]
tap = ["KEY_THAT_WILL_BE_PRESSED_WHEN_INPUT_KEY_IS_TAPPED"]

Here is the configuration file that I use for my laptop, as my Tab and Number 2 keys do not work.

device_name = "AT Translated Set 2 keyboard"

[[remap]]
input = ["KEY_END"] output = ["KEY_2"]

[[remap]]
input = ["KEY_HOME"]
output = ["KEY_TAB"]

You can save the file by hitting CTRL + X, then Y and then Enter.

Now, you can log out and log back in and test your new configuration. If everything went perfectly, your remapped keys should work as expected.

Please visit the official repository on GitHub if you have any questions or need a detailed documentation.

Other Options

There is a tool called xmodmap, but it works only on X11.

References


Comments

Recent Posts

How to Bypass CGNAT - Exposing your home server to the internet with TLS/SSL pass through

07 October 2023 | Linux Guide, Privacy, Self-hosting

You've set up a home server, and are hosting some services like Vaultwarden, or Jellyfin, or perhaps Nextcloud. But now, you want to share it...

Read More

Remap keyboard keys using evremap

21 May 2023 | Linux Guide

Sometimes a key on your keyboard stops working, and you may not have the time or motivation to fix it or get it fixed. Or...

Read More

Proton VPN Linux Guide – How to install, configure, use and auto-connect?

19 May 2023 | Linux Guide, Privacy

The official Proton VPN Linux client lacks a lot of features, like changing the connection protocol, quickly connecting to the fastest server of a specific...

Read More

MusicOther ProjectsPrivacy PolicyAbout