Remapping both mouse and keyboard to a gamepad
Since Halloween, I have been really enjoying Frictional Games' Amnesia on Ubuntu. My next goal is to get the other offerings they have.
Unfortunately, there is not a gamepad setting for this game (and many others out there). I know there is software like rejoystick that allows the mapping of keyboard keys to a gamepad. However, since this game incorporates the mouse, is there a solution to map both over?
Thanks in advance.
Update: I have found on playdeb.net QJoypad. It allows the mapping of both keyboard and mouse. Unfortunately, I still seem to have trouble with the mouse when entering Amnesia.
Following Grumbel's answer, I tried xboxdrv solution with the support of his link and specially this page:
1. Install xboxdrv 0.8.2 from Ubuntu Software Center.
Install also uinput and joydev if needed.
I did it this way sudo modprobe uinput
+ sudo modprobe joydev
2. Need to know the event of the gamepad:
Launch udevadm monitor --udev
and then plug the game pad :
$ udevadm monitor --udev
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [6722.377700] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1 (usb)
UDEV [6722.383264] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0 (usb)
UDEV [6722.383333] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/0003:046D:C218.0003 (hid)
UDEV [6722.383389] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/0003:046D:C218.0003/hidraw/hidraw1 (hidraw)
UDEV [6722.387123] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/input/input10 (input)
UDEV [6722.399284] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/input/input10/event8 (input)
UDEV [6722.412128] add /devices/pci0000:00/0000:00:1d.3/usb5/5-1/5-1:1.0/input/input10/js0 (input)
I conclude that my gamepad's event is /dev/input/event8
3. Display names of every keys, axis, buttons of the gamepad.
The idea is to launch xboxdrv
and test every buttons and note the result on paper.
$ sudo xboxdrv --evdev /dev/input/event8 --evdev-debug
Your Xbox/Xbox360 controller should now be available as:
/dev/input/js1
/dev/input/event9
Press Ctrl-c to quit, use '--silent' to suppress the event output
EV_ABS ABS_X 128
EV_ABS ABS_Y 128
...
In my case the result is:
4. Set the config file
Create a xboxdrv-mouse.ini file to set X Y axis and left and right mouse button.
Here I set gamepad buttons 2 for left mouse button and 3 for right mouse button:
[xboxdrv]
evdev=/dev/input/event8
silent=true
[evdev-absmap]
ABS_X=x1
ABS_Y=y1
[ui-axismap]
x1=REL_X:10
y1=REL_Y:-10
[evdev-keymap]
BTN_THUMB=a
BTN_THUMB2=b
[ui-buttonmap]
a=BTN_LEFT
b=BTN_RIGHT
# EOF #
Note that value for REl_X and REL_Y seems to define the speed of the mouse, and by defining a negative value it invert the axis (see here for REL_Y)
An other example with more button definition
[xboxdrv]
evdev=/dev/input/event8
silent=true
[evdev-absmap]
ABS_X=x1
ABS_Y=y1
ABS_HAT0X=x2
ABS_HAT0Y=y2
[ui-axismap]
x1=REL_X:10
y1=REL_Y:-10
x2=KEY_LEFT:KEY_RIGHT
y2=KEY_DOWN:KEY_UP
[evdev-keymap]
BTN_TRIGGER=x
BTN_TOP=y
BTN_THUMB=a
BTN_THUMB2=b
BTN_PINKIE=rt
BTN_BASE2=rb
BTN_TOP2=lt
BTN_BASE=lb
BTN_BASE3=back
BTN_BASE4=start
[ui-buttonmap]
x=KEY_KPENTER
y=KEY_SPACE
a=BTN_LEFT
b=BTN_RIGHT
rt=KEY_KP8
rb=KEY_KP2
lt=KEY_KP6
lb=KEY_KP4
back=KEY_LEFTSHIFT
start=KEY_RIGHTCTRL
# EOF #
5. Launch it
sudo xboxdrv --config xboxdrv-mouse.ini
To avoid launching it with sudo
, create a udev rule.
CONCLUSION
It works fine, it's the best solution for me.
The solution is QJoyPad. As I stated in my update on the question, it does allow the mapping of both keyboard and mouse.
Amnesia is a little bit of an oddball in the configuration because the game uses, according to their forum, relative mouse movements. The solution is launch the game via a terminal after typing in export SDL_VIDEO_X11_DGAMOUSE=0
. After doing so, my test with the mouse worked fine.
By the way, the controller I am using with QJoyPad is a Logitech Dual Action.
To map a gamepad to mouse, try js2mouse.
In Ubuntu 11.10, qjoypad doesn't seem to work properly, because a left-click on its icon in the notification area triggers a right-click menu with no way to access setup. You can, however, use Rejoystick (also available in PlayDeb). The first time you run it (running rejoystick
) you assign keys to your gamepad's buttons, then save. Next you run rejoystick -d
and you won't get a GUI, rejoystick is running in the background and will use your gamepad's buttons for the assigned keys.