January 22, 2016

Disabling mouse feature from composite remote device

Categories: Sysadmin, The Real Life.

The remote of my Kodi based media center recently died and I bought a replacement one, identified as a 2.4GHz Fly Air Mouse Wireless Keyboard Motion Sensor Remote Control on Banggood.

The device is viewed as a composite one consisting of a keyboard and a mouse. The mouse feature can be disabled/enabled using a mouse lock button on the remote.

Only problem, when the device wakes up from standby mode, the mouse device is always enabled and the cursor moves on screen, selecting whatever is below it… Pressing the mouse lock button stops the madness, but as the mouse enter standby mode after a few seconds of inactivity the same problems happen over and over again.

I fixed this by software. This was a 2 steps process:

  1. Reduce the mouse sensitivity so that the cursor does not move when the device moves;
  2. Trigger keypresses on mouse clicks.

Reducing the mouse sensitivity

The first idea that comes to mind is to reduce the mouse sensitivity in dramatic proportions so that important mouse motion produce a cursor move of no more than 0 pixels. This can be achieved by setting a custom transformation matrix to the mouse device. The default transformation matrix is an identity one (table 1).

Table 1 — default identity matrix

Replacing it with the matrix from table 2 gives appropriate results.

Table 2 — customized matrix

This can be setup using the following Xorg configuration (for example in /usr/share/X11/xorg.conf.d/80-airmouse.conf on a GNU/Linux system):

Section "InputClass"
    Identifier "Air Mouse"
    MatchProduct "AliTV Remote V1 Airmouse"
    MatchIsPointer "on"
    Option "TransformationMatrix" "0.00000001 0 0 0 0.00000001 0 0 0 1"

Triggering keypresses on mouse clicks

The OK and Return buttons do not behave the same way depending on the mouse lock status. When the mouse is enabled, they trigger left and right clicks, otherwise they trigger Return and Escape keypresses. Since the mouse is enabled when the device wakes up, it is necessary to remap mouse clicks to keyboard events, otherwise you still have to lock the cursor over and over again.

xbindkeys(1) is the tool of choice for this purpose. It can catch mouse events and trigger an action when then occur. xvkbd(1) can then be used to send keypress events. xbindkeys(1) is configured with the ~/.xbindkeysrc file as follows:

"xvkbd -text 'r'"

"xvkbd -text 'e'"

Button 1 (left click) will send a Return key keypress, and button 3 (right click) will send a Escape key keypress. Then we just have to start xbindkeys(1) when Kodi starts. This depends on the way Kodi starts on your system, in my case desktop application autostart is disabled so I achieved this throught simple a ~/.kodi/userdata/autoexec.py script:

import os

No Comments Yet

Comments RSS feed | Leave a Reply…