Emulate mouse click when hitting a key

Solution 1:

The solution is

xmodmap -e "keycode 115 = Pointer_Button2"

Now my Home key is doing left click and behaves just as if I hit the mouse click and I can keep the key pressed and it highlights (copies) as expected.

I also mapped my End key to be middle click, so I can use it to paste:

xmodmap -e "keycode 110 = Pointer_Button1"

Note that it is necessary to have "mousekeys" (mouse emulation using the numeric keypad) enabled for this to work. "mousekeys" can be toggled by pressing Shift+NumLock or set explicitly by running:

dconf write /org/gnome/desktop/a11y/keyboard/mousekeys-enable true
dconf write /org/gnome/desktop/a11y/keyboard/mousekeys-enable false

Solution 2:

Most desktops have some accessibility settings that will control the mouse with the keyboard already built-in, like XFCE has them in it's All Settings -> Accessibility -> Mouse -> Mouse Emulation, that uses the keyboard number pad so the 5 key does exactly what you're trying to do.

If I recall, gnome, cinnamon and mate have similar features under something like "Accessibility" or assistive technology, etc. Or an installable program/package like mousetweaks ("mouse accessibility enhancements for the GNOME desktop") or keynav (but I couldn't get it to work on xfce).

Or, if your touchpad still works ok (just not the buttons) you could just do a tap for a single click, a tap & then hold for a click & drag, a double-tap = double click... and if they don't work there should be a line or two in the terminal that should get those to work (don't remember them offhand now). I wouldn't want to write my own script when there are a few other options that should work