uinput-mapper Use Cases

A note on permissions; you need to have write access to /dev(/input)?/uinput and read access to the device you want to read. You can achieve this either by running uinput-mapper as root; or by executing the following command:

chmod 666 /dev/uinput /dev/input/event*

Or by other means (adding groups, editing udev, etc)

Cloning any input device

Cloning any device (over the network) can be done without any configuration.

./input-read /dev/input/event7 -D | ./input-create

Or, equivalently, over the network (using ssh):

./input-read /dev/input/event7 -D | ssh user@remote /path/to/input-create

The above command will forward input device 7 over the network to the remote machine "remote".

Or, the other way around (cloning an device from machine "remote" to your local machine)

ssh user@machine /path/to/input-read /dev/input/event7 -D | ./input-create

The same can be done without ssh, but is considered unsafe (because uinput-mapper uses pickle), so only do it on networks that you trust.

On the machine that will recieve the clone:

nc -l -p 8000 | ./input-create

On the machine that will forward its device:

./input-read /dev/input/event7 > /dev/tcp/remote/8000

When using bash, or, with netcat:

./input-read /dev/input/event7 -D | nc remote -p 8000

Mobile phone touchscreen as input device on your machine

This is the configuration I used to forward my Nokia N900's touchscreen:

   1 from uinputmapper.cinput import *
   2 
   3 config = {
   4         (0, EV_ABS) : {
   5             ABS_X : {
   6                 'type' : (0, EV_ABS),
   7                 'code' : ABS_X,
   8                 'value' : None,
   9                 'prop' : {
  10                     'max' : 3000,
  11                     'min' : 200,
  12                     'flat' : 0,
  13                     'fuzz' : 0
  14                 }
  15             },
  16             ABS_Y : {
  17                 'type' : (0, EV_ABS),
  18                 'code' : ABS_Y,
  19                 'value' : None,
  20                 'prop' : {
  21                     'max' : 3000,
  22                     'min' : 200,
  23                     'flat' : 0,
  24                     'fuzz' : 0
  25                 }
  26             }
  27         }
  28 }
  29 
  30 names = {
  31     0 : 'Touchscreen'
  32 }
  33 
  34 def config_merge(c, n):
  35     for k, v in config.iteritems():
  36         if k in c:
  37             c[k].update(v)
  38         else:
  39             c[k] = v
  40 
  41     # Uncomment this to make touch click too
  42     c[(0, EV_KEY)][BTN_TOUCH] = {
  43             'type' : (0, EV_KEY),
  44             'code' : BTN_TOUCH,
  45             'value' : lambda x: 0
  46     }
  47     n.update(names)

Using this command (-C because N900 has Python 2.5):

ssh root@nokia-n900 uinput-mapper/input-read /dev/input/event3 -CD | ./input-create -C

Joystick Hat as mouse pointer

In absolute mode, configuration:

   1 from uinputmapper.cinput import *
   2 
   3 
   4 """
   5 Configuration for a simple Microsoft SideWinter Game Pad Pro USB version 1.0
   6 ... as ABS input pointer device
   7 """
   8 
   9 config = {
  10         (0, EV_KEY): {
  11             BTN_A: {
  12                 'type' : (0, EV_KEY),
  13                 'code' : BTN_MOUSE,
  14                 'value' : lambda x: 0 if x == 0 else 1
  15             }
  16         }
  17 }
  18 
  19 names = {
  20     0 : 'ABS Mouse'
  21 }
  22 
  23 def config_merge(c, n):
  24     del c[(0, EV_KEY)]
  25     c.update(config)
  26     n.update(names)

Command:

./input-read -D /dev/input/event9 | ./input-create configs/sidewinder.py

In relative mode:

   1 from uinputmapper.cinput import *
   2 
   3 """
   4 Configuration for a simple Microsoft SideWinter Game Pad Pro USB version 1.0
   5 ... as REL input pointer device
   6 """
   7 
   8 
   9 config = {
  10         (0, EV_KEY): {
  11             BTN_A: {
  12                 'type' : (0, EV_KEY),
  13                 'code' : BTN_MOUSE,
  14                 'value' : lambda x: 0 if x == 0 else 1
  15             }
  16         },
  17         (0, EV_ABS) : {
  18             ABS_X: {
  19                 'type' : (0, EV_REL),
  20                 'code' : REL_X,
  21                 'value' : lambda x: x / 7,
  22             },
  23             ABS_Y: {
  24                 'type' : (0, EV_REL),
  25                 'code' : REL_Y,
  26                 'value' : lambda x: x / 7,
  27             }
  28         }
  29 }
  30 
  31 names = {
  32     0 : 'REL Mouse'
  33 }
  34 
  35 def config_merge(c, n):
  36     del c[(0, EV_KEY)]
  37     del c[(0, EV_ABS)]
  38     c.update(config)
  39     n.update(names)

Command:

./input-read -D /dev/input/event9 | ./input-create configs/sidewinder-rel.py

Forwarding your mouse and keyboard to another device (or mobile phone)

In this case, I forward my mouse and keyboard from my netbook to my N900:

./input-read /dev/input/event5 /dev/input/event7 -DC | ssh root@nokia-n900 uinput-mapper/input-create -C

No configuration required; but I needed to install packages on my N900 to properly support external keyboards and mice. Thanks to the Maemo community for making this so easy!

Turning a specific mouse button (on your thinkpad) into a meta key

   1 from uinputmapper.cinput import *
   2 
   3 config = {
   4         (0, EV_KEY) : {
   5             BTN_MIDDLE : {
   6                 'type' : (0, EV_KEY),
   7                 'code' : KEY_RIGHTMETA,
   8                 'value' : None
   9             }
  10         }
  11 }
  12 
  13 names = {
  14     0 : 'Fingerboard'
  15 }
  16 
  17 def config_merge(c, n):
  18     c.clear()
  19     c.update(config)
  20     n.update(names)

uinput-mapper/UseCases (last edited 2014-02-03 18:34:27 by MerlijnWajer)