Remapping Keyboard Keys to mouse buttons on Ubuntu 18.04

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.

1

1 Answer

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like