Swapping the mouse axis

The problem was the following: how to use a MouseTrapper positioned vertically on an armrest? This would most likely be the best solution for an individual with an injured shoulder, as this would allow one to control the mouse without moving his the shoulder at all and so. However, to be able to do this, one needs to be able to rotate the mouse input 90(in other words swap the X. and Y. axis).

This was first done on Microsoft Windows computer. The solution can be found here. In addition solution was needed for GNU/Linux machine. There are several ways of doing this under GNU/Linux. To rotate the input of all devices, one could simply enter a single option in xorg.conf. To ensure that one specific device is always rotated when it is connected to the computer one could ensure this by creating a file in /etc/hal/fdi/policy/. If this is of interest, this blog post might be of interest.

However, in this case best solution was to create the script that would allow the user to rotate the input from the single device of interest when needed. The solution to this was to use the xinput-command. Finding out that this was the command needed was not simple, since most information about how to rotate the mouse is about how to rotate the mouse in conjunction with rotating the screen. Doing that is normally done with the xrandr command. To only rotate the mouse one instead needs to use the command:


xinput list

will give a list of all the devices available. Next one can see what settings are available to be changed for a given device, using the command


xinput list-props "name of the device"

or


xinput list-props [ID of device]

ones the settings one wants to change have been found, one may change them using the command


xinput set-int-prop "name of the device" "name of setting" 8 x

where x is one or more numbers representing the setting of choice. Note that both “name of the device” and “name of setting” can be switched out with the ID of the device and the ID of the setting.

In the given example we were interested in two settings: “Evdev Axes Swap” and “Evdev Axis Inversion” (since the mousetrapper would be upside down). Also note the use a for-loop instead of just setting the settings directly. The reason for this is that the mousetrapper for some reason adds two devices with the same name. Thus setting the setting directly results in an error message. Instead we you through the devices with the given name, and change their settings addressing them by ID instead of name.


#!/bin/sh

for number in `xinput list | awk '/Trapper Data AB/ {print $6}' | sed s/id=//`
	do
		if [ `xinput list-props $number | awk '/Evdev Axes Swap/ {print $5}'` -eq 1 ]; then
		xinput set-int-prop $number "Evdev Axes Swap" 8 0
		xinput set-int-prop $number "Evdev Axis Inversion" 8 0 0
	else
		xinput set-int-prop $number "Evdev Axes Swap" 8 1
		xinput set-int-prop $number "Evdev Axis Inversion" 8 0 1
	fi
done

Last modified: 20.07.2010
Table of content