To map a key on your keyboard as the middle mouse button, you can use a xbindkeys
tool called , which lets you customize the behavior of your keyboard and mouse buttons. You'll also need a xdotool
tool 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:
- Install
xbindkeys
andxdotool
:
sudo apt-get install xbindkeys xdotool
- Create a new
xbindkeys
configuration file:
xbindkeys --defaults > $HOME/.xbindkeysrc
- Open the file with a text editor
.xbindkeysrc
, for example:
nano ~/.xbindkeysrc
- At the bottom of the file, add the following:
"xdotool click 2"
F5
This maps the F5 key as the middle mouse button.
-
Save and close the file.
-
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 xbindkeys
to use this custom key on every boot. You can xbindkeys
do this by adding to your list of startup applications.
principle
xbindkeys
And xdotool
the 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.
-
xbindkeys
is 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,xbindkeys
catches 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. -
xdotool
is a command-line tool that simulates keyboard input and mouse activity, among other things on the X server. When you run axdotool
command, it sends a request to the X server asking it to simulate a specific keyboard or mouse event. For example,xdotool click 2
the command sends a request to the X server to simulate a middle mouse button click.
So, when you press the F5 key, xbindkeys
this event is caught, and xdotool click 2
the 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.