Pages de Cédric VINCENT

Js2mouse

Official page is here.

Js2mouse converts joystick events into mouse events, so the user can use his joystick/gamepad as a pointer instead of the mouse. It works with any kind of joystick (analogic or digital) and with any kind of program (X, GPM, etc.). Js2mouse doesn't need root privileges. It can emulate PS/2 and IMPS/2 protocols, and joystick keys can be assigned.

Download Js2mouse here : js2mouse-040208.tar.gz

Installation

  1. download the latest sources : http://www.freshmeat.net/projects/js2mouse/
  2. enter the following commands into a terminal :
    tar -xvzf js2mouse-YYMMDD.tar.gz
    cd js2mouse/js2mouse
    make
    su -c "make install"    # enter root's password, if necessary
    

Quick explanations

How to launch Js2mouse

  1. log as root : this is only necessary if you use Js2mouse default options.
  2. enter the following commands into a terminal :
    js2mouse &
    exit
    
    At this point, Js2mouse is running in the background.

How to modify X configuration

  1. log as root (if necessary)
  2. replace these lines :
    Option "Protocol" "_YOUR_MOUSE_PROTOCOL_"
    Option "Device" "/dev/_YOUR_MOUSE_DEVICE_"
    
    by :
    Option "Protocol" "_PROTO_"   #_PROTO_ is PS/2 or IMPS/2
    Option "Device" "/dev/j2m_fifo"
    
    Option "ZAxisMapping" "4 5"   #only if you use the IMPS/2 protocol
    
  3. restart X (on the fly : CTRL+ALT+BACKSPACE)

How to modify GPM configuration

It depends on your Linux distribution, so this is the most independant explanation that I can give... Adapt your own configuration files :

  1. log as root (if necessary)
  2. enter the following commands into a terminal :
    gpm -k
    gpm -m /dev/j2m_fifo -t ps2
    

More details

Configurations for others programs

For the moment Js2mouse emulates PS/2 and IMPS/2 protocols, so adapt the configuration for these protocols...

Js2mouse without root privileges

You do not need to run Js2mouse with root privileges if you specify to use a "virtual mouse character device" (the fifo) into a directory where you've got write-permissions :

js2mouse -f $HOME/j2m_fifo

Js2mouse as a second pointer with X

  1. add this section into the X configuration file :
    Section "InputDevice"
    
    	Identifier "Mouse2"
    	Driver "mouse"
    
    	Option "Protocol" "_PROTO_" #_PROTO_ is PS/2 or IMPS/2
    	Option "Device" "/dev/j2m_fifo"
    
    	Option "ZAxisMapping" "4 5" #only if you use IMPS/2 protocol
    
    EndSection
    
  2. into the Section "ServerLayout", add :
    InputDevice "Mouse2" "SendCoreEvents"
    
  3. restart X (on the fly : CTRL+ALT+BACKSPACE)

Js2mouse as a second pointer with GPM

It depends on your Linux distribution, so this is the most independant explanation that I can give... Adapt your own configuration files :

  1. log as root (if necessary)
  2. enter the following commands into a terminal :
    gpm -k
    gpm -m /dev/_YOUR_REAL_MOUSE_DEV_ -t _ITS_PROTOCOL_ -M -t ps2 -m /dev/j2m_fifo
    

Keys remapping for Js2mouse

I wrote this functionality on the fly, so this is experimental...

  1. edit /etc/j2m_map, format is :
    JOYSTICK_EVENT = MOUSE_EVENT
    
  2. JOYSTICK_EVENTs are :
    button_1
    button_2
    ...
    button_NUMBER_OF_BUTTON
    axe_1
    axe_2
    ...
    axe_NUMBER_OF_AXES
    
  3. MOUSE_EVENTs are :
    click_left
    click_right
    click_middle
    click_extra1
    click_extra2
    wheel_up
    wheel_down
    move_horizontal
    move_vertical
    

Default keys mapping (i.e. without -r argument) is:

button_1 = click_left
button_2 = click_right
button_3 = click_middle
button_4 = wheel_up
button_5 = wheel_down
button_6 = click_extra1
button_7 = click_extra2
axe_1 = move_horizontal
axe_2 = move_vertical

Js2mouse options

-h show this help
-d <dev> use specified device, default : /dev/input/js0
-f <fifo> use specified fifo, default : /dev/j2m_fifo
-v <n> verbose level, 0 to 3, default : 3
-t <n> poll timeout in ms, default : 20
-r active keys remapping, default : disable
-p use specified mouse protocol, default : ps2

Integrate Js2Mouse into the Linux kernel (a.k.a j2mdev : EXPERIMENTAL)

Installation

  1. download the latest sources : http://www.freshmeat.net/projects/js2mouse/
  2. enter the following commands into a terminal :
    tar -xvzf js2mouse-YYMMDD.tar.gz
    cd js2mouse/j2mdev
    cp j2mdev-linux-2.6.1.patch /_WHERE_ARE_LINUX_SOURCES_/
    cd /_WHERE_ARE_LINUX_SOURCES_/
    patch -p0 <j2mdev-linux-2.6.1.patch
    cd linux
    make menuconfig
    # say Y or M to [Device Driver]->[Input DeviceSupport]->[Joystick->mouse converter interface]
    # recompile the kernel or modules
    

Load the module (if necessary)

  1. log as root.
  2. load your joystick driver, for instance :
    modprobe gamecon gc=0,7
    
  3. load j2mdev :
    modprobe j2mdev
    
  4. create (if necessary) related character device :
    mknod /dev/input/j2m0 c 13 200
    mknod /dev/input/j2m1 c 13 201
    mknod /dev/input/j2m2 c 13 202
    mknod /dev/input/j2m3 c 13 203
    

Parameters

You can specify the buttons map (2 to 5 arguments) when loding the module j2mdev :

btn=_left_,_right_,_middle_,_extra1_,_extra2_

You can specify the axes map (2 arguments) too :

abs=_horizontal_,_vertical_

You can also specify the refresh time between two reads :

refresh=_time_

For instance :

modprobe j2mdev refresh=10 btn=305,307,308

To know which values represent your buttons/axes, take a look at kernel log :

dmesg

FAQ

GPM doesn't work with Js2mouse in IMPS2 protocol, why ?

GPM does a "ioctl call" when using IMPS2 protocol, but only kernel can handle this call...

How to use js2mouse with DirectFB ?

Js2mouse doesn't work with DirectFB, but you can use j2mdev.

X takes 3 seconds to start when I use Js2mouse...

X needs to initialize the driver, but Js2mouse can't handle this kind of initialization. This doesn't appear with the kernel version (j2mdev).

I use the "gamecon" driver and the system seems to slow down, why ?

This driver scan the parallel port too fast... In "/usr/src/linux/drivers/char/joystick/gamecon.c" replace :

#define GC_REFRESH_TIME HZ/100

by

#define GC_REFRESH_TIME HZ/10

Then rebuild the module or kernel. It works fine with my PSX gamepad. This problem doesn't appear with Linux 2.6.

I want to use j2mdev with a linux version that doesn't seem to be supported, how to do ?

All linux-2.6.XX kernel should be supported, do :

cp j2mdev-linux-2.6.1.patch /_WHERE_ARE_LINUX_SOURCES_/linux-2.6.XX
cd /_WHERE_ARE_LINUX_SOURCES_/linux-2.6.XX
patch -p1 < j2mdev-linux-2.6.1.patch
make menuconfig
# say Y or M to [Device Driver]->[Input Device Support]->[Joystick->mouse converter interface]
# recompile the kernel or modules

Can you provide a pre-compiled j2mdev kernel module ?

No :) ! But I can help you to compile yours !

Integrate Js2Mouse directly into Links and other programs

Integrate Js2mouse into Links-Hacked-030709

  1. download the Links-Hacked-030709 sources (Js2mouse is directly integrated in next version) : links-hacked-030709.tgz and links-fonts-new.tgz
  2. enter the following commands into a terminal :
    tar -xvzf js2mouse-YYMMDD.tar.gz
    cd js2mouse/contrib/links-hacked-030709
    cp links-hacked-030709-joyfb.diff /_WHERE_ARE_LINKS-HACKED_SOURCES_/
    cd /_WHERE_ARE_LINKS-HACKED_SOURCES_/
    patch -p0 > links-hacked-030709-joyfb.diff
    #compile Links-hacked-030709
    

Integrate Js2mouse into Links-2.1pre11 (ONLY WITH js2mouse-030919)

  1. download the Links-2.1pre11 sources (other versions are not tested) : links-2.1pre11.tar.gz
  2. unpack Links-2.1pre11 sources
  3. do "./configure --enable-graphics [OPTIONS]"
  4. download the latest sources : http://www.freshmeat.net/projects/js2mouse/
  5. unpack Js2mouse sources into the root directory of Links-2.1pre11
  6. replace "framebuffer.c" with "js2mouse/contrib/links-2.1pre11/framebuffer.c"
  7. go into js2mouse/src and enter "make -f Makefile.linksfb"
  8. add "js2mouse/src/*.o" into Makefile of Links-2.1pre11, to the variable "links_OBJECTS"
  9. do "make", "make install"

Integrate Js2mouse into other programs

  1. take a look at the previous source code integration.
  2. just do it ;)