Creating Custom Raspberry Pi OS Keyboard Shortcuts

发布人是

Raspberry Pi single-board computers have an excellent GUI called Raspberry Pi OS (formerly Raspbian). This makes getting started easy, but what if you want to launch an often-used program with a certain keyboard combination, rather than dragging your mouse to the corresponding icon? Or what if your keyboard is missing a certain button that you need, like “print screen?”

The good news is that assigning custom Raspberry Pi keyboard shortcuts is definitely possible, though you’ll need to do a bit of text file editing. Open up your terminal by clicking the appropriate icon in Raspberry Pi OS, or better yet with Ctrl-Alt-t, to get started on your custom input journey.

The example below shows one custom input example. How it works is discussed further in the sections below:

RP Keyboard Shortcuts Image 2

    <!-- Custom Keyboard Shortcuts -->

    <keybind key="A-p">

      <action name="Execute">

        <command>scrot</command>

      </action>

    </keybind>

    <keybind key="C-A-c">

      <action name="Execute">

        <command>chromium-browser</command>

      </action>

    </keybind>

Advanced Settings: XML Modification

In the terminal, enter sudo nano /etc/xdg/openbox/lxde-pi-rc.xml. Scroll down to the line that says <keyboard>, or you can search for it by pressing Ctrl-w. On a new line following the </chainQuitKey> tag, enter the comment <!-- Custom Keyboard Shortcuts --> (or similar) to let you keep track of your new modifications.

Before actually making any modifications, scroll down through the lines following, noting the shortcut format. Breaking things down, the <keybind key="XXYY"> tag triggers a comand. The <action name="AABB"> tag then specifies what kind of action will be taken. Here we'll be using Execute as the action, in order to launch a program. Finally, the <Command> tag specifies that actual command to be executed.

Custom Keybind for Raspberry Pi

For the keybind key= tag, the format is "key1-key2-key3..." in whatever combination you desire. Note that the number of keys can be more or fewer than the three shown there, depending on your needs. Special keys have their own terminology, including:

  • A for Alt,
  • C for Ctrl,
  • S for shift
  • W for the "Windows" key

 

So Alt-p would be A-p, or if you want to use Ctrl as well, you'd add C-A-p here.

Command

RP Keyboard Shortcuts Image 3

The "%U" or other similar text following the main command can often be omitted.

Once triggered, the command line executes whatever comes after. If you need an alternate to printscreen, you'd type in scrot between the tags—the same command that you'd use to launch the printscreen program from the terminal. Other commands can be found by right-clicking on a taskbar icon, selecting properties, then the Desktop Entry tab. To launch VLC media player, for instance, you'd enter the line: <command>/usr/bin/vlc</command>, with the launch command between the opening and closing tags.

Exit and save, then reboot to activate your custom keyboard shortcuts.

Pi Keyboard Shortcut Application

It’s possible that you may never need to use a custom shortcut command, as the Raspberry Pi Operating System has several built-in, and you’ll often be using the terminal anyway. I got started down this road when working on the Raspberry Pi/Analog Discovery 2 oscilloscope. My Bluetooth keyboard didn’t have an actual print screen button, and I needed a way to get screenshots for the documentation found here. At the time, I just plugged in another keyboard, but this is a rather inelegant solution.

Whether you’re missing an important (to you) key or need to run a certain program in a flash, having the ability to make custom Raspberry Pi OS shortcuts is a great option to have at your disposal.

最新消息

Sorry, your filter selection returned no results.

请仔细阅读我们近期更改的隐私政策。当按下确认键时,您已了解并同意艾睿电子的隐私政策和用户协议。

本网站需使用cookies以改善用户您的体验并进一步改进我们的网站。此处阅读了解关于网站cookies的使用以及如何禁用cookies。网页cookies和追踪功能或許用于市场分析。当您按下同意按钮,您已经了解并同意在您的设备上接受cookies,并给予网站追踪权限。更多关于如何取消网站cookies及追踪的信息,请点击下方“阅读更多”。尽管同意启用cookies追踪与否取决用户意愿,取消网页cookies及追踪可能导致网站运作或显示异常,亦或导致相关推荐广告减少。

我们尊重您的隐私。请在此阅读我们的隐私政策。