I would like to use keyboard buttons for left and right mouse clicks. I found this answer that describes remapping mouse buttons to keyboard keys. Can I use this method 'in reverse' to map keyboard keys to mouse buttons? E.g. F1 key = left click, F2 key = right click. I'd like the remap to apply on startup.
2 Answers
This can be done with xdotool
if you run Xorg. ydotool
will also work on Wayland.
For example, to simulate a mouseclick with the left button:
xdotool click 1 # left click
or
ydotool click left
Bind these commands to a shortcut key, e.g. using "Settings" - "Keyboard" for the default Ubuntu desktop. On xorg
, you can also use hotkey daemons that are independent of the desktop, like xbindkeys
or sxhkd
. Note, however, that these may be unreliable if you switch keyboard layouts, or when the computer wakes from a suspended state.
You can use the remapper deamon keyd for this purpose. See this answer for installation, usage and tips.
After installation, use the config below.
[ids]
*
[main]
f1 = leftmouse
f2 = middlemouse
f3 = rightmouse