Mouse movement via the keyboard with xdotool and xbindkeys

13-09-2016 | Remy van Elst


Table of Contents


I had a request from a friend to figure out how she could use her mouse via the keyboard. Normally you would use Mouse Keys, but she uses a kinesis freestyle2 which has no numpad. By using xbindkeys together with xdotool we can use our own key combination to move the mouse keys.

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get a $5 VPS for 2 months free (as in, you get $10 credit). (referral link)

Make sure the packages are installed:

apt-get install xdotool xbindkeys

Use your window manager to let xbindkeys start at startup.

Append the following to your ~/.xbindkeysrc file:

# ALT SHIFT 
# 10 up
"xdotool mousemove_relative --sync -- 0 -10"
Mod1+Shift+w

# ALT SHIFT S
# 10 down
"xdotool mousemove_relative --sync -- 0 10"
Mod1+Shift+s

# ALT SHIFT A
# 10 left
"xdotool mousemove_relative --sync -- -10 0"
Mod1+Shift+a

# ALT SHIFT D
# 10 right
"xdotool mousemove_relative --sync -- 10 0"
Mod1+Shift+d

# ALT SHIFT Q
# left click
"sleep 1 && xdotool click 1"
Mod1+Shift+q

# ALT SHIFT E
# right click
"sleep 1 && xdotool click 3"
Mod1+Shift+e

This will let you use the WASD combined with ALT and SHIFT to move the mouse. The Q and E keys can be used to left and right click, but that is with a delay of one second. Otherwise some applications like firefox interpret the SHIFT as an instruction to open a new window which is not what we want in this use case.


Tags: accessibility, automation, x, xbindkeys, xdotool, xorg,