Search:  
Gentoo Wiki

HOWTO_Joystick_as_Mouse


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Beginning

You have just bought a cheap USB joystick/gamepad and want to use it with your Gentoo Linux as a Mouse/Keyboard. This might be useful for both normal desktop usage (painting etc.) or for gaming: if joystick configuration within game is too much complex you can simply have the events translated to mouse and keyboard.

This HOWTO will help you in the process of setting the gamepad/joystick up with your Gentoo Linux.

Please note that the USB joystick/gamepad configuration is also described in Joystick.

Do not plug your USB joystick/gamepad, do it only when required.

Kernel options

These are the kernel options that you need.

Code: Linux Kernel 2.6 and USB
Device Drivers -->
 Input Device Support -->
  <*> Joystick Interface
  <*> Event Interface
   [*] Joysticks
 USB Support -->
  <*> Support for Host-side USB
   [*] USB device filesystem
  <*> EHCI HCD (USB 2.0) support
  <*> OHCI HCD support
  <*> UHCI HCD (most Intel and VIA) support
  <*> USB Human Interface Device (full HID) support
   [*] HID input layer support

See also:

Packages

Install joystick and qjoypad packages.

Code:
Emerge
emerge joystick qjoypad

Calibrate joystick

Open a terminal to calibrate your joystick. Plug-in the joystick and then run jscal.

Code:
Calibration
 jscal /dev/js0 --calibrate

Follow the on-screen instructions.

Once finished, run the following.

Code:
Calibration script generation
 jscal /dev/js0 -p > usbgp-cal.sh
 chmod +x usbgp-cal.sh

Once done that, you will have a script called usbgp-cal.sh which contains the calibration code for your joystick. It might be useful to have it executed each time the joystick is plugged; this is a job for an udev rule.

Udev rule for joystick calibration

Hardware identification for udev

While your joystick/gamepad is plugged in, identify it with the following:

Code:
Listing peripherals
 $ ls -l /dev/input/by-id/*event-joystick

lrwxrwxrwx 1 root root 9 19 lug 14:56 usb-0079_USB_Gamepad-event-joystick -> ../event6

 $ 

Note the interesting part: usb-0079_USB_Gamepad-event-joystick -> ../event6. This USB gamepad is mounted as event6 (this may change in your system).

Now let's find the exact product name. Replace event6 with the event device seen above.

Code:
Hardware product name
 $ echo "'$(</sys/class/input/event6/subsystem/input6/name)'"

'USB Gamepad '

 $ 

So our identification string is 'USB Gamepad ', with the trailing space (some hardware products may have it).

Create a file 99-usbgp.rules (or whatever name you prefer) in /etc/udev/rules.d/.

Replace 'USB Gamepad ' with your actual device identification string.

File: /etc/udev/rules.d/99-usbgp.rules
SUBSYSTEM=="input", KERNEL=="js*", SUBSYSTEMS=="input", ATTRS{name}=="USB Gamepad ", RUN+="/etc/udev/scripts/usbgp-cal.sh"

Now move/copy or symlink your usbgp-cal.sh script into the /etc/udev/scripts/ directory (create it because it does not exist).

This way the joystick will be calibrated each time we plug it in.

See also:

Joypad mapping to mouse/keyboard

Here comes the cool part, which we will accomplish through [1].

Run qjoypad and configure your joystick layout so that specific keyboard/mouse presses are generated each time a joystick action is performed.

See also:

Mapping with Xorg

It is also possible to map gamepad/joystick keys to mouse/keyboard using Xorg, but this is only useful if you do not plan to change the keys anymore, because you would else need to restart Xorg each time (not very flexible).

This is an example xorg.conf section for a joystick configuration.

File: /etc/X11/xorg.conf
...
# **********************************************************************
Section "InputDevice"
	Identifier	"USB_Gamepad_XFCE"
	Driver	"joystick"
	Option "Device" "/dev/input/js0"
	Option "SendCoreEvents" "true"

Option "MapAxis1"     "mode=none"
Option "MapAxis2"     "mode=none"
Option "MapAxis3"     "mode=none"
Option "MapAxis4"     "mode=relative axis=X"
Option "MapAxis5"     "mode=relative axis=Y"
Option "MapAxis6"     "mode=none"

## L2
Option "MapButton5" "key=37" ## Ctrl_L
## R2
Option "MapButton6" "key=70" ## F4
## R1
Option "MapButton8" "key=102" ## key right

## L1
Option "MapButton7" "key=100" ## key left
## START
Option "MapButton10" "key=36" ## Enter

## SELECT
Option "MapButton9" "key=64" ## Alt_L
## B3
Option "MapButton3" "button=1" ## left mouse click
## B2
Option "MapButton1" "button=2" ## right mouse click
## B1
Option "MapButton2" "button=3" ## middle mouse click
## B4
Option "MapButton4" "key=23" ## Tab

EndSection

# **********************************************************************
...

See man joystick for more informations about this Xorg configuration.

If you use qjoypad, it is not necessary to configure Xorg (I do not suggest it: it could cause multiple keys to be pressed!).

Known Issues

Cursor hung to top-left corner

This glitch causes the joystick/gamepad buttons to not work and the mouse cursor to be moved to the top-left corner of the display.

Apart from the non-functional gamepad, you can also verify that you are affected by this bug because your Xorg.0.log file will contain lines like these:

(II) evdev brain: Rescanning devices (1).
(**) Option "SendCoreEvents"
(**) usbmouse-usb-0000:00:1d.0-2/input0: always reports core events
(II) usbmouse-usb-0000:00:1d.0-2/input0: Found 6 absolute axes.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Configuring as pointer.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Found 0 relative axes.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Configuring as pointer.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Found 42 mouse buttons
(**) usbmouse-usb-0000:00:1d.0-2/input0: Configuring 6 absolute axes.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Checking button DIGI_STYLUS (330)
(II) usbmouse-usb-0000:00:1d.0-2/input0: Checking bit 330
(EE) usbmouse-usb-0000:00:1d.0-2/input0: AbsoluteTouch: 'DIGI_Touch' does not exist.
(**) usbmouse-usb-0000:00:1d.0-2/input0: Configuring in Absolute mode.
(**) usbmouse-usb-0000:00:1d.0-2/input0: AbsoluteScreen: 0.
(**) usbmouse-usb-0000:00:1d.0-2/input0: Configuring 2 relative axes.
(II) usbmouse-usb-0000:00:1d.0-2/input0: Configured 42 mouse buttons

42 buttons for my usb mouse?! I don't have any USB mouse plugged...the joystick has been (incorrectly) seen as a mouse.

To fix this problem, simply tighten your Device option in the InputDevice section for your USB mouse. For example, use a line like this:

  Option "Device" "/dev/input/by-id/usb-Logitech_Optical_USB_Mouse-event-mouse"

Cursor constantly moving towards the top-left corner

You have not calibrated your joystick. See #Calibrate Joystick

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Joystick_as_Mouse"

Last modified: Thu, 04 Sep 2008 22:45:00 +0000 Hits: 1,728