How to change keyboard shortcuts on Raspberry Pi

Keyboard shortcuts are a terminal user’s best friend. They make life easier for those of us that spend a lot of time tinkering in our command line terminal or those that always seem to have at least a dozen windows open simultaneously. On the default Raspberry Pi OS, there are already a few handfuls of keyboard shortcuts ready to use. And even more can be configured.

In this tutorial, we will cover the step by step instructions on creating custom keyboard shortcuts on the Raspberry Pi. This will specifically apply to the Raspberry Pi OS. We will also go over a brief list of keyboard shortcuts which are configured out of the box and ready to use, which we think are handy to know. Let’s get started!

In this tutorial you will learn:

  • How to change keyboard shortcuts on the Raspberry Pi
How to change keyboard shortcuts on Raspberry Pi
How to change keyboard shortcuts on Raspberry Pi
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Raspberry Pi
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to change keyboard shortcuts on Raspberry Pi step by step instructions




The default Raspberry Pi OS uses the LXDE desktop environment, so these instructions will be specifically for that type of GUI. Other desktop environments will have a different process that you need to follow in order to customize keyboard shortcuts.

Keyboard shortcut legend

The following legend will be necessary in order to understand what some of the keyboard shortcuts mean:

Keyboard shortcut Description
A Alt key
C Ctrl key
S Shift key
Print Print screen key
Return Enter key

Step by step instructions

  1. All of the Raspberry Pi’s keyboard shortcuts are configured inside of the /etc/xdg/openbox/lxde-pi-rc.xml file. However, we can’t make direct changes to this file because it will be overwritten upon future reboots. So, the first step is to create a copy of this file and store it inside of the user’s home directory. In that file, we can make changes which will persist across reboots. Execute the following commands to make a copy:
    $ mkdir -p $HOME/.config/openbox
    $ cp /etc/xdg/openbox/lxde-pi-rc.xml $HOME/.config/openbox
    
  2. Next, open up the lxde-pi-rc.xml file with nano or your preferred text editor:
    $ nano $HOME/.config/openbox/lxde-pi-rc.xml
    
  3. Once inside this file, hit Ctrl + W on your keyboard to perform a search. Type ‘keyboard’ and press Enter to go directly to the correct section that contains keyboard shortcuts.

    Find the section that contains keyboard shortcuts inside of the configuration file
    Find the section that contains keyboard shortcuts inside of the configuration file



  4. Each keyboard shortcut starts and ends with a <keybind> directive. Inside of this, there are <action> tags which specify what action should be taken when the specified keyboard shortcut is triggered. There may also be a <command> tag which will control what command gets executed. Let’s take a look at an example below, where A-F4 triggers the Close action. This is a default key bind and is present on most or all systems.
    This keyboard shortcut configures the Alt + F4 keybind to close the current window
    This keyboard shortcut configures the Alt + F4 keybind to close the current window

    Using the legend above, we can see that A represents the Alt key, and Close will exit the current window.

  5. Using the legend above, and the directives taught in the previous steps, you should have everything you need in order to start configuring the existing shortcuts. You can also create your own shortcuts by adding new lines to the file. Here is an example:
    <keybind key="C-A-c">
    <action name="Execute">
    <command>chromium</command>
    </action>
    </keybind>
    

    The code above programs the keyboard shortcut Ctrl + Alt + C to execute the chromium command. In other words, the Chromium browser is opened whenever we press this keyboard shortcut.

  6. When you are finished making the changes, save the file and exit by pressing Ctrl + X and hitting Enter twice. Then, reboot your Raspberry Pi for the changes to take effect:
    $ sudo reboot
    

Closing Thoughts




In this tutorial, we saw how to change keyboard shortcuts on a Raspberry Pi system. This pertains to the Raspberry Pi OS specifically, which runs the LXDE desktop environment. We also learned how to create our own custom keyboard shortcuts. Note that the file we edit is a per user basis.



Comments and Discussions
Linux Forum