How to turn a key on the keyboard into a middle-click function? (ubuntu)

To map a key on your keyboard as the middle mouse button, you can use a xbindkeystool called , which lets you customize the behavior of your keyboard and mouse buttons. You'll also need a xdotooltool called , which simulates keyboard input and mouse activity.

Here's how to install both tools and set a key on your keyboard (for example, F5) to emulate the middle mouse button:

  1. Install xbindkeysand xdotool:
sudo apt-get install xbindkeys xdotool
  1. Create a new xbindkeysconfiguration file:
xbindkeys --defaults > $HOME/.xbindkeysrc
  1. Open the file with a text editor .xbindkeysrc, for example:
nano ~/.xbindkeysrc
  1. At the bottom of the file, add the following:
"xdotool click 2"
  F5

This maps the F5 key as the middle mouse button.

  1. Save and close the file.

  2. Run the following command to start xbindkeys:

xbindkeys

Now, whenever you press the F5 key, the system will simulate a click of the middle mouse button.

NOTE: You may need to run it on boot xbindkeysto use this custom key on every boot. You can xbindkeysdo this by adding to your list of startup applications.

principle

xbindkeysAnd xdotoolthe working principle of these two tools is based on the X Window System (also known as X11 or X), which is the graphical user interface (GUI) standard on Linux and Unix systems.

  1. xbindkeysis a program that can capture keyboard and mouse button events and run specified commands when these events occur. It works by listening to events sent by the X server. When you press or release a key or mouse button, the X server sends an event, xbindkeyscatches this event, and looks in its configuration file ( .xbindkeysrc) for an entry that matches the event. If so, it runs the command associated with that event.

  2. xdotoolis a command-line tool that simulates keyboard input and mouse activity, among other things on the X server. When you run a xdotoolcommand, it sends a request to the X server asking it to simulate a specific keyboard or mouse event. For example, xdotool click 2the command sends a request to the X server to simulate a middle mouse button click.

So, when you press the F5 key, xbindkeysthis event is caught, and xdotool click 2the command is run, which sends a request to the X server, simulating a middle mouse button click event. That's why you can paste text by pressing F5.

Guess you like

Origin blog.csdn.net/m0_57236802/article/details/131883352