Can I bind mouse buttons to act as keyboard keys?

Mapping keyboard keys to function like mouse buttons is easy to do with xmodmap, but how would I do the reverse?

How can I bind, say, the side button (button 8 or 9) to act as left ctrl?

I know xmodmap can swap around the mouse keys, and bind the keyboard to mouse keys, but not how to bind the mouse to keyboard keys.

I managed to figure out a way using sxhkd and xdotool

in sxhkdrc:

button8
    xdotool keydown 37
@button8 + ctrl
    xdotool keyup 37

the + ctrl on key release is needed because when button 8 is pressed, ctrl is also pressed, which meanse when you release it it is ctrl + button 8 instead of button 8, withuot it the key release wouldn’t work.

With X11, all things are possible.

I use Easystroke - this lets me set my side buttons as I like. I set my ‘fwd’ button as an instant button to resize windows, and the ‘back’ button to move windows… saves having to hold a keyboard key and click to do the same job.

The added bonus here is that - whatever you want to do is likely possible, get ready for bed:
2023-09-29 14:15:16

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.