Controlling the mouse in the X Window System¶
Somebody asked me today if I knew of any programs to control the mouse in X using their keyboard. I was actually quite shocked how many people don’t know that X has a method for doing this built-in, hence this little tip.
- Press shift+numlock to turn mouse emulation on. And pressing shift+numlock again will turn the emulation off.
- Move the pointer with the numeric pad.
- 8 for up
- 2 for down
- 4 for left
- 6 for right
- 7 for diagonally up-left
- 9 for diagonally up-right
- 1 for diagonally down-left
- 3 for diagonally down-right
- To accelerate the movement hold the alt key down then press the movement keys.
- To emulate a mouse click hit 5 on the numeric pad.
- If you want to hold the click use 0 on the numeric pad. Then hit 5 to release.
- To choose which mouse button 5 and 0 behave like press:
- / on the numeric pad to choose button 1.
- * on the numeric pad to choose button 2.
- - on the numeric pad to choose button 3.
Using this method produces the exact same results as using a real pointing device as far as all X applications are concerned. It even produces the correct press and release events. To see for yourself use xev.
Some stupid window managers and desktop environments disable the standard keys(and some other features) in X, so don’t complain to me if you have problems in KDE3 for example. Either complain to the KDE people, or fix the keyboard handling in KDE yourself.