Drag and drop by dragging the mouse on the desk is probably the single most physically strenuous effort an office employee or typist or any computer user has to perform, particularly when done repetitively day in day out. Here is how to migrate this destructive gesture to keyboard in Linux.
Method 1: xdotool
xdotool is a program that can be used to modify pretty much all window and peripheral operations under Xorg. For press-and-hold left mouse button, which is the starting point of drag, the normal code is
xdotool mousedown 1. For some reason in my system this does not work as desired. What works is:
xdotool mousedown 1 && sleep 0.5
Put this code to be triggered by some keybind and it will emulate holding left mouse button (click and hold). To drag, move the mouseball (or trackball – highly recommended to acquire one or some).
To drop at the desired spot, the easiest thing to do is to briefly click on the actual left mouse button. However, there is also a corresponding
xdotool mouseup 1 that can again be configured to a keybind.
Method 2: xmouseless
There is a fairly recent program that can easily replace the entire mouse with keyboard. Many thanks to the author of
xmouseless, which can emulate both mouse clicks and scrolling by keyboard and, along with it, also drag and drop. The most recommended method for installing is
git clone https://github.com/jbensmann/xmouseless
sudo make install.
After installing and launching, the default operations are as follows:
- Pointer moves are under i, j, k, and l
- Clicks are under f, d, and s (left, middle and right respectively)
- n and p or plus and minus to scroll down and up, h and g to scroll vertically
- To accelerate mouse moves, there are left Control (slowest), a, left Alt, and left Super.
To drag to select text, move the pointer to the needed starting point (i, j, k, l), hold f and simultaneously press l or j, depending to which direction you need to select.
To drag and drop a link, move the pointer to the link, hold f and simultaneously do the pointer moves again. To drop, just let go of the keyboard.
To exit and get your normal keyboard back, press q or Escape.
To configure the defaults, read and modify config.h, recompile and reinstall.
The only downside of
xmouseless is that it requires some getting used to, if you are not familiar with keyboard layers, but it should not be too hard. For example, Caps Lock is effectively a keyboard layer: The keys that used to do lowercase are now doing uppercase. Similarly, Shift, AltGr, and Compose key are keyboard layers.
Users of compact keyboards are always forced to configure some layer to be able to access the function keys, numpad, and more. Keyboard layers are also familiar to those who need to switch alphabets and writing systems on the keyboard.
xmouseless is just another such layer.