Guide: Advanced Controller Mappings
-
@mediamogul That is very useful information indeed. It makes the whole runcommand scenario so much more flexible. No need to reserve
runcommand-onstart
purely for xboxdrv any longer. -
Another nice use case that I'm really liking is invoking a script that kills the current map and launches another. This is particularly useful for having a universal map for a game system that can switch on the fly between digital, analog and four-way restricted controls.
-
@mediamogul That's interesting. When and for what emulator do you use this? Could you please show an example?
-
@spud11 said in Guide: Advanced Controller Mappings:
When and for what emulator do you use this?
Almost any emulator could benefit from it, as a surprising amount of retro games play so much more smoothly with 4-way restricted controls, so the ability to toggle it on and off through the use of multiple maps is a great advantage. One unfortunate exception is AdvanceMAME, due to it only recognizing input that was available at launch. Amiberry has this same requirement, so it's out as well, but everything else I've tried so far works very well.
Could you please show an example?
Sure. Below is my Atari 2600 map for Stella that now has the following features combined.
- 8-way digital directional control (Dpad/Left Thumb)
- 4-way digital directional control (Dpad/Left Thumb)
- Full analog directional control (Left Thumb with Modifier Toggle)
- Full Atari Keypad control (Right Thumb with Modifier buttons)
- Atari BoosterGrip control ('X' and 'A' buttons)
- One button cycled difficulty switch for two players ('LB' and 'RB')
- Stella user interface Control ('RT' Modifier)
default.sh
Initial launch map:#!/bin/bash sudo killall xboxdrv sleep 1 sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv \ --evdev /dev/input/by-path/platform-3f980000.usb-usb-0:1.2:1.0-event-joystick \ --detach-kernel-driver \ --force-feedback \ --dpad-as-button \ --trigger-as-button \ --deadzone-trigger 15% \ --deadzone 4000 \ --device-name "Logitech Rumblepad 2 (xboxdrv)" \ --silent \ --axismap -Y1=Y1,-Y2=Y2 \ --buttonmap tl^toggle=tl \ --buttonmap tr^toggle=tr \ --evdev-absmap ABS_X=x1,ABS_Y=y1,ABS_Z=x2,ABS_RZ=y2,ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \ --evdev-keymap BTN_THUMB2=a,BTN_THUMB=b,BTN_TOP=x,BTN_TRIGGER=y,BTN_BASE3=back,BTN_BASE4=start,BTN_TOP2=lb,BTN_PINKIE=rb,BTN_BASE5=tl,BTN_BASE6=tr,BTN_BASE=lt,BTN_BASE2=rt \ --ui-axismap X1=KEY_LEFT:KEY_RIGHT,Y1=KEY_UP:KEY_DOWN \ --ui-axismap X2=KEY_1:KEY_2,Y2=KEY_3:KEY_Q,lt+X2=KEY_W:KEY_E,lt+Y2=KEY_A:KEY_S,rt+X2=KEY_D:KEY_X,rt+Y2=KEY_Z:KEY_C \ --ui-buttonmap a=KEY_LEFTBRACE,b=KEY_B,x=KEY_RIGHTBRACE,y=KEY_Y,lt=KEY_UNKNOWN,rt=KEY_UNKNOWN,tl=KEY_UNKNOWN,tr=KEY_UNKNOWN,du=KEY_UP,dd=KEY_DOWN,dl=KEY_LEFT,dr=KEY_RIGHT,start=KEY_T,back^delay:325=KEY_U \ --ui-buttonmap lb=cycle-key:KEY_GRAVE:KEY_R,rb=cycle-key:KEY_5:KEY_6 \ --ui-axismap tl+x1=REL_X:15,tl+y1=REL_Y:15 \ --ui-buttonmap tr+b=BTN_LEFT,tr+a=BTN_RIGHT \ --ui-buttonmap back+start=KEY_ESC,back+x=KEY_TAB,back+lb=KEY_F11,back+rb=KEY_F9,back+dr=KEY_F10,back+b=KEY_LEFTCTRL+KEY_R,back+a=KEY_PAUSE \ --ui-buttonmap back+y=exec:/opt/retropie/configs/all/xboxdrv/script-functions/shared/raspi2png.sh \ --ui-buttonmap lt+rt=exec:/opt/retropie/configs/all/xboxdrv/script-functions/emulators/stella/4waystrict.sh \ --ui-buttonmap rt+a=KEY_ENTER,rt+b=KEY_ESC,rt+du=KEY_UP,rt+dd=KEY_DOWN,rt+dl=KEY_LEFT,rt+dr=KEY_RIGHT,rt+y=KEY_LEFTSHIFT+KEY_TAB,rt+x=KEY_TAB,rt+lb=KEY_LEFTSHIFT+KEY_LEFT,rt+rb=KEY_LEFTSHIFT+KEY_RIGHT \ --ui-buttonmap guide=void \ &
4waystrict.sh
called from initial map by pressing 'LT+RT':#!/bin/bash sudo killall xboxdrv sleep 1 sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv \ --evdev /dev/input/by-path/platform-3f980000.usb-usb-0:1.2:1.0-event-joystick \ --detach-kernel-driver \ --force-feedback \ --dpad-as-button \ --trigger-as-button \ --deadzone-trigger 15% \ --deadzone 4000 \ --device-name "Logitech Rumblepad 2 (xboxdrv)" \ --silent \ --four-way-restrictor \ --axismap -Y1=Y1,-Y2=Y2 \ --buttonmap tl^toggle=tl \ --buttonmap tr^toggle=tr \ --evdev-absmap ABS_X=x1,ABS_Y=y1,ABS_Z=x2,ABS_RZ=y2,ABS_HAT0X=dpad_x,ABS_HAT0Y=dpad_y \ --evdev-keymap BTN_THUMB2=a,BTN_THUMB=b,BTN_TOP=x,BTN_TRIGGER=y,BTN_BASE3=back,BTN_BASE4=start,BTN_TOP2=lb,BTN_PINKIE=rb,BTN_BASE5=tl,BTN_BASE6=tr,BTN_BASE=lt,BTN_BASE2=rt \ --ui-axismap X1=KEY_LEFT:KEY_RIGHT,Y1=KEY_UP:KEY_DOWN \ --ui-axismap X2=KEY_1:KEY_2,Y2=KEY_3:KEY_Q,lt+X2=KEY_W:KEY_E,lt+Y2=KEY_A:KEY_S,rt+X2=KEY_D:KEY_X,rt+Y2=KEY_Z:KEY_C \ --ui-buttonmap a=KEY_LEFTBRACE,b=KEY_B,x=KEY_RIGHTBRACE,y=KEY_Y,lt=KEY_UNKNOWN,rt=KEY_UNKNOWN,tl=KEY_UNKNOWN,tr=KEY_UNKNOWN,du=KEY_UP,dd=KEY_DOWN,dl=KEY_LEFT,dr=KEY_RIGHT,start=KEY_T,back^delay:325=KEY_U \ --ui-buttonmap lb=cycle-key:KEY_GRAVE:KEY_R,rb=cycle-key:KEY_5:KEY_6 \ --ui-axismap tl+x1=REL_X:15,tl+y1=REL_Y:15 \ --ui-buttonmap tr+b=BTN_LEFT,tr+a=BTN_RIGHT \ --ui-buttonmap back+start=KEY_ESC,back+x=KEY_TAB,back+lb=KEY_F11,back+rb=KEY_F9,back+dr=KEY_F10,back+b=KEY_LEFTCTRL+KEY_R,back+a=KEY_PAUSE \ --ui-buttonmap back+y=exec:/opt/retropie/configs/all/xboxdrv/script-functions/shared/raspi2png.sh \ --ui-buttonmap lt+rt=exec:/opt/retropie/configs/all/xboxdrv/script-functions/emulators/stella/default.sh \ --ui-buttonmap rt+a=KEY_ENTER,rt+b=KEY_ESC,rt+du=KEY_UP,rt+dd=KEY_DOWN,rt+dl=KEY_LEFT,rt+dr=KEY_RIGHT,rt+y=KEY_LEFTSHIFT+KEY_TAB,rt+x=KEY_TAB,rt+lb=KEY_LEFTSHIFT+KEY_LEFT,rt+rb=KEY_LEFTSHIFT+KEY_RIGHT \ --ui-buttonmap guide=void \ &
Notice that the default map can then be called back in 4-way restricted, completing the toggle. The only actual difference between the two maps is the addition of
--four-way-restrictor
and calling the alternate script. -
Hello, first of all, thank you very much for the work you do in this forum. I've been here a short time and there are always doubts that I can solve thanks to you. I'm new and I still have a lot to learn. I have a Rpi3 with the last versión of retropie.
I would like to ask you about a problem with a controller that I currently have. Recently I bought this keyboard:
https://www.amazon.com/dp/B077MDCSFQ/ref=twister_B07BSBJCBY?_encoding=UTF8&psc=1
As you can see, it has two buttons like LR but they are not part of the key map of the keyboard (event0), but of the mouse (event1), as well as the reproduction and volume buttons, and retropie and retroarch can't read it.
Looking for a long time I found xboxdrv and I think it is the only solution that can help me.
My goal is to be able to use the LR buttons and the playback buttons as if they were part of an xbox360 controller, and to configure the keymap of emulators SNES or PS together with the keyboard. Also maybe be able to use the touchpad as a joystick. The L and R keys of the keyboard are working like left and right click of the mouse.
I have found questions and answers about joypad as a mouse, but not the other way around. I have tried to configure following the guide but I have not managed to make it work.
I would like to get some help or experience, a way or a guide, to be able to get it. I can show you the logs or events if necesary. Thank you very much, and sorry if I can´t explain myself as well as you do, I still don't know about programming this tool. -
What you're looking to do is very unique, even for xboxdrv. Also, in my opinion, this device will never make a great controller, or at least one that will be worth the effort it'll take to make it work. However, I believe it would be possible to achieve both objectives in theory. However, I'm not completely sure they can be combined into one functional control scheme, as I've never attempted anything like this. First the touchpad as joystick. The map for such a thing would look something like:
/opt/retropie/supplementary/xboxdrv/bin/xboxdrv --evdev /dev/input/your-mouse-event-here \ --evdev-keymap BTN_LEFT=KEY_PICKONE,BTN_RIGHT=KEY_PICKONE \ --ui-axismap x1=REL_X,y1=REL_Y \ --mimic-xpad \ --silent
Make sure to map two mouse buttons to keys that don't already exist on the mini keyboard. At that point you would technically have two keyboards, but RetroArch will make use of them as if they were one. To find two keys that don't exist on the mini keyboard, type
/opt/retropie/supplementary/xboxdrv/bin/xboxdrv --help-key
into the command line and look for two that might work. After that, you'll need to of course map the keyboard keys you want to use in RetroArch, as well as create the udev rule mentioned in the guide at the end of section 3A. Finally, the joystick from the virtual controller will need to be mapped to the analog joystick of player one in RetroArch as well. When it's all said and done, you'll hopefully have two keyboards and a virtual XBox controller acting in tandem to control the player one events. This is a complete Frankenstein method that I believe should work, but again, I'm not positive. All in all, I'd recommend against it, as I don't think it's a great solution, but if you're really set on using this keyboard as a controller, it may be worth a shot.
-
@mediamogul
Thanks for de reply. Of course I know the difficulties of creating something like that, and I know that it isn't the best controller, but I want to use it to travel or occasional plays.
I've tried to follow your last message without success, I used the following code:sudo killall xboxdrv sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv \ --evdev /dev/input/event1 \ --silent \ --mimic-xpad \ --evdev-keymap BTN_LEFT=rb,BTN_RIGHT=lb \ --ui-axismap x1=REL_X,y1=REL_Y \
I tried again more times with different configurations but I can not find the problem so that Retropie recognizes the right and left buttons, the axis of the joystick does not seem to work either.
I used trigger-as-button iterating configurations and I thought it worked because it showed the name (end of section 3A of the guide), but at the time of mapping, it didn't recognize the same buttons either.
Although I do not expect to get it, thanks for the help! -
Try and see if all the buttons and axis are registering in the newly created joystick with
jstest
. The command would be:jstest /dev/input/jsX
Where 'X' is the number of the xboxdrv-created controller.
-
@mediamogul
It give me this backJoystick (Xbox Gamepad (userspace driver)) has 6 axes (X, Y, Rx, Ry, Hat0X, Hat0Y) and 13 buttons (BtnX, BtnY, BtnTL, BtnTR, BtnTR2, BtnSelect, BtnStart, BtnMode, BtnThumbL, BtnThumbR, ?, ?, ?). Testing ... (interrupt to exit) Axes: 0: 0 1: 0 2: 0 3: 0 4: 0 5: 0 Buttons: 0:off 1:off 2:off 3:off 4:off 5:off 6:off 7:off 8:off 9:off 10:off 11:off 12:off
And nothing testing, neither evtest.
What that it means? -
So, while the testing interface was up, you didn't get any response from using the touchpad, or from pressing the buttons?
-
@mediamogul
Exactly, I don't get any reponse. I have tested with all the controllers that enable xboxdrv without success. -
I'm afraid that may mean it's not going to work. Usually, if there's an issue, xboxdrv will simply refuse to create the virtual controller and throw an error. The fact that it is created, but has no response likely means there's nothing to troubleshoot and that the two are just not compatible.
-
@mediamogul
Well, thanks for the answer, I'll try to do some tests even though we can not do anything. The best way to test the changes is as follows?sudo killall xboxdrv sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv ((...changes...)) reboot
Thanks for the help!
-
@javisousa20 said in Guide: Advanced Controller Mappings:
The best way to test the changes is as follows?
On something like this, the best advice I can give is to keep throwing ideas at the problem as you have them. Whenever I find myself in uncharted territory, trial and error is often the mother of resolution.
-
@mediamogul
Hi, I think the problem is when I reboot to initialize xboxdrv. I have tried to use the following codesudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv --evdev /dev/input/event1 --evdev-debug --evdev-keymap BTN_LEFT=LB,BTN_RIGHT=RB
It give me this back when I press the
BTN_LEFT
, also withBTN_RIGHT
EV_KEY BTN_LEFT 1 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:1 RB:0 LT: 0 RT: 0 EV_KEY BTN_LEFT 0 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 EV_KEY BTN_LEFT 1 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:1 RB:0 LT: 0 RT: 0
It seems that the emulation to the LB button works, but when I restart to initialize xboxdrv, the result is lost:
sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv --evdev /dev/input/event1 --evdev-debug EV_KEY BTN_LEFT 1 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 EV_KEY BTN_LEFT 0 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
There may be something that I am doing wrong, Do I have to write it in rc.local?
-
I believe you're right. xboxdrv is allowing the map to happen without error, but when the virtual controller is produced, those buttons don't seem to be communicating as they should. If I had to guess, it may be because you're mapping a mouse event. I've never done that myself and while it's technically possible and xboxdrv doesn't complain, it's just not communicating for some reason.
-
@mediamogul
Is there any way to start xboxdrv without rebooting? Or what is the way to start the configuration of xboxdrv at start? Is it to write the code in rc.local? Because I'm having troubles in that case -
You can always kill it at any time with
sudo killall xboxdrv
When testing, you can just created a script, say in your home folder and launch it to see if it's working. If not, kill it, alter it and launch it again.
-
@mediamogul said in Guide: Advanced Controller Mappings:
You can always kill it at any time with
sudo killall xboxdrv
When testing, you can just created a script, say in your home folder and launch it to see if it's working. If not, kill it, alter it and launch it again.
It would not work for what I try to get, xboxdrv does not modify the first virtual event (ex: event2, js0) if I have not used
killall
before, either through rc.local or a script or directly from the xboxdrv command, but that creates a new event (and new js) that does not appear in /dev /input because it always exceeds the limit of defined controllers for the driver. The problem was that I could not run xboxdrv after I had used the killall command, only if I rebooted... or I don't know how.
But I think I've got it, I should try a script like you said, but for now I've managed to make it work by making the following change inrc.local
:sudo /opt/retropie/supplementary/xboxdrv/bin/xboxdrv \ --evdev /dev/input/event1 \ --silent \ --mimic-xpad \ --trigger-as-button \ --evdev-keymap BTN_LEFT=LB,BTN_RIGHT=RB,KEY_CONFIG=LT,KEY_SEARCH=RT,KEY_PLAYPAUSE=A,KEY_PREVIOUSSONG=X,KEY_NEXTSONG=B,KEY_VOLUMEUP=Y,KEY_VOLUMEDOWN=back "/opt/retropie/supplementary/xboxdrv/bin/xboxdrv" --daemon --detach --dbus disabled --detach-kernel-driver --id 0 --led 2 --deadzone 4000 --silent --trigger-as-button --next-controller --id 1 --led 3 --deadzone 4000 --silent --trigger-as-button exit 0
The first call is my design for xboxdrv and the second one is the default one when enabling the driver from retropie config.
The problem with this method now comes from that to include that code in rc.local, when loading backpieces at the beginning, instead of entering emulationstation runs xboxdrv as expected from command line, but remains stopped in its last sentence:Your Xbox/Xbox360 controller should now be available as: /dev/input/js0 /dev/input/event2 Press Ctrl-C to quit
But I can't do nothing to quit, skip or enter in emulationstation directamente. (Or I may not know how)
I can only enter emulationstation using SSH. There I can map all the keys and buttons without problems (although I still have to try the touchpad as a joystick).
It is an advance, I would like to take advantage of your knowledge in programming that I don't have to finish polishing it, there may be more interested people. -
@javisousa20 said in Guide: Advanced Controller Mappings:
But I can't do nothing to quit, skip or enter in emulationstation directly. (Or I may not know how)
Ok sorry, I forgot the &. Now it's working well!
When I want to use lxde desktop I can't use the keyboard or mouse, how can I end the xboxdrv process automatically when I want to access the desktop and restart it when I go back to retropie?
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.