Pages

02 December 2012

multinput (Multiple mouse/keyboard input with xinput)


I have got a dual head main desktop. I always thought it would be nice to be able to use several keyboards and mice working independently. Today I learnt how to easily configure multiple input with xinput only to discover that my settings will always disappear after every reboot or logout.


Well, the logical next step was to write an script to automatically activate multiple input but since I also want to be able to deactivate it at will I wrote two parts "start" and "stop". So the usage goes:
 $ multinput start
or
 $ multinput stop
or
 $ multinput restart
The script can either be run automatically at startup (anacron comes to mind) or manually.
Note: Be warned that this script is for personal use only. Feel free to adapt it to your own needs. I hope you like it and that it is useful for you too.
Here it is:
#!/bin/sh

set -e

# Script for personal use, to set multiple mouse/keyboard input on "odd".
#
# It uses xinput, so read its man page for more info. In order to list your
# devices type "xinput list"

MOUSE2="PIXART USB OPTICAL MOUSE"
KEYBOARD2="AT Translated Set 2 keyboard"

usage ()
{
echo "Type 'multinput start' to use multiple mice/keyboards."
echo "Type 'multinput stop' to stop using multiple mice/keyboards."
}

start ()
{
xinput create-master multinput
xinput reattach "$MOUSE2" "multinput pointer"
xinput reattach "$KEYBOARD2" "multinput keyboard"
} 
# Leave devices floating.    
 stop ()
{
xinput remove-master "multinput pointer"
}

if [ "$1" = "start" ]
    then
        start
        exit 0
elif [ "$1" = "stop" ]
    then
        stop
        exit 0
elif [ "$1" = "restart" ]
    then
        stop
        start
        exit 0
else
        usage
        exit 0
fi