Mapping a Game Controller in Kodi

Home Forums RetroPie Project Everything else related to the RetroPie Project Mapping a Game Controller in Kodi

RetroPie has a new website and forum. Please visit https://retropie.org.uk/ for the new site. The new forum is located at https://retropie.org.uk/forum/. This forum is left here as a read-only archive.

This topic contains 27 replies, has 8 voices, and was last updated by Profile photo of noratio noratio 1 year, 2 months ago.

Viewing 28 posts - 1 through 28 (of 28 total)
  • Author
    Posts
  • #106586
    Profile photo of dudleydes
    dudleydes
    Participant

    After posts here and at Reddit, I thought I’d share a method for mapping your game controller to use in Kodi without the need to recompile.

    Build Linux Joystick Mapper binary

    Download the source from the following link:

    http://sourceforge.net/projects/linuxjoymap/

    Copy the joymap-0.2 folder to the home directory of your pi and build the binary with the following commands:

    cd joymap-0.2
    make

    This will create a binary called loadmap.

    Get Joystick Information

    Joystick selection by number (jsX) is broken in Linux Joystick Mapper so the vendor and product identifier must be used. This info can be found by running the command:

    cat /proc/bus/input/devices
    The output for my PS3 controller was:

    I: Bus=0003 Vendor=054c Product=0268 Version=0111
    N: Name="Sony PLAYSTATION(R)3 Controller"
    P: Phys=usb-bcm2708_usb-1.3.2/input0
    S: Sysfs=/devices/platform/bcm2708_usb/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/0003:054C:0268.0001/input/input2
    U: Uniq=
    H: Handlers=js0 event2 
    B: PROP=0
    B: EV=1b
    B: KEY=7 0 0 0 0 0 0 0 0 0 0 0 0 ffff 0 0 0 0 0 0 0 0 0
    B: ABS=7fffff00 27
    B: MSC=10

    The information required is in the first line. For the PS3 controller, the vendor code is 054c and the product code is 0268.

    Create the Mapper File

    Documentation for creating a mapper file can be found in /doc/config.pdf.

    To map a joystick button to a key press, a line needs to added for each mapping as below:

    button vendor=0xXXXX product=0xYYYY src=joy_button_num target=kbd button="key_press"
    where
    XXXX is the vendor code
    YYYY is the product code
    joy_button_num is the joystick button number as defined in jstest
    “key_press” is the key press to map

    The values for key presses can be found in the keys.txt in the source code folder.

    The default keyboard controls for Kodi can be found at the link below:

    http://kodi.wiki/view/Keyboard_controls

    To keep things tidy, I created a new folder, joymap, in the home directory. I copied the loadmap binary built earlier to the joymap folder. I then created a text file, kodi.map, with the following contents:

    # PS3 controller mapper file for Kodi
    
    # Navigation
    # D-pad to navigate; X to select and circle to go to previous menu
    button vendor=0x054c product=0x0268 src=4 target=kbd button="up"
    button vendor=0x054c product=0x0268 src=5 target=kbd button="right"
    button vendor=0x054c product=0x0268 src=6 target=kbd button="down"
    button vendor=0x054c product=0x0268 src=7 target=kbd button="left"
    
    button vendor=0x054c product=0x0268 src=14 target=kbd button="enter"
    button vendor=0x054c product=0x0268 src=13 target=kbd button="esc"
    
    # Triangle to bring up conextual menu
    button vendor=0x054c product=0x0268 src=12 target=kbd button="c"
    
    # Play Media
    # R1 to play/pause and L1 to stop
    button vendor=0x054c product=0x0268 src=11 target=kbd button="space"
    button vendor=0x054c product=0x0268 src=10 target=kbd button="x"
    
    # Exit Kodi by pressing Select and Start
    button vendor=0x054c product=0x0268 src=0 target=kbd button="leftctrl"
    button vendor=0x054c product=0x0268 src=3 target=kbd button="end"

    Please note this mapping may not be complete for your needs. Also I have not found a way to map analogue sticks to key presses.

    Execute Mapper with Kodi

    To load the mapper file with Kodi, I edited kodi.sh in the /roms/ports folder as follows:

    #!/bin/bash
    sudo /home/pi/joymap/loadmap /home/pi/joymap/kodi.map &
    /opt/retropie/supplementary/runcommand/runcommand.sh 0 "kodi-standalone" "kodi"
    sudo killall loadmap
    sleep 1

    Permissions on /dev/uinput are required to run the mapper program. I tried the instructions below to set the permissions to pi but they did not work so I ran the mapper program as sudo to get round this.

    https://tkcheng.wordpress.com/2013/11/11/changing-uinput-device-permission/

    The killall command (run as sudo) will stop the mapper program before returning to ES.

    The sleep command is to prevent a ES error which I guess was occurring because of a conflict of joystick control between the mapper program and ES.

    When you launch Kodi, you will get failed to grab device/failed to lock device messages. You can ignore these – Kodi and your mapping will work fine.

    #107375
    Profile photo of jonnygall
    jonnygall
    Participant

    I have not tried this with Kodi yet, but I tried it out on a game called lbreakout2 and works great with a controller. I was always frustrated I had to play with a keyboard. Thanks for telling me about this.

    One thing is trying to get the mouse portion to work. I have a nintendo 64 controller and I was trying to map the mouse to the analog stick. I did get the mouse to work but what happened was the cursor would re calibrate itself to the upper left corner of the screen, and I wished it wouldn’t do that. I looked at the example map in the joymap folder but I’m still stumped.

    EDIT:
    Mouse is working, left and right clicks work. Still have the same problem of the cursor re-calibrating. Also, regular button keys work but as soon as I move with the analog stick the buttons stop (excluding the left and right click).

    • This reply was modified 1 year, 6 months ago by Profile photo of jonnygall jonnygall.
    #107423
    Profile photo of dudleydes
    dudleydes
    Participant

    I have tried lbreakout2 (built from http://lgames.sourceforge.net/index.php?project=LBreakout2) and have not observed any of the behaviour you mention in your post.

    Here is the mapping file I used for a PS3 controller

    # Mapping for lbreakout2 for PS3 Controller
    
    # Map mouse
    axis vendor=0x054c product=0x0268 src=0 target=mouse axis=0
    axis vendor=0x054c product=0x0268 src=1 target=mouse axis=1
    
    button vendor=0x054c product=0x0268 src=14 target=mouse button=0
    button vendor=0x054c product=0x0268 src=15 target=mouse button=1
    
    # Actions
    button vendor=0x054c product=0x0268 src=0 target=kbd button="esc"
    button vendor=0x054c product=0x0268 src=3 target=kbd button="enter"
    
    button vendor=0x054c product=0x0268 src=10 target=kbd button="x"
    button vendor=0x054c product=0x0268 src=11 target=kbd button="c"
    
    button vendor=0x054c product=0x0268 src=12 target=kbd button="y"
    #107445
    Profile photo of jonnygall
    jonnygall
    Participant
    # mapper file for lbreakout2
    
    # navigation
    button vendor=0x06f7 product=0x0001 src=10 target=kbd button="up"
    button vendor=0x06f7 product=0x0001 src=11 target=kbd button="down"
    button vendor=0x06f7 product=0x0001 src=12 target=kbd button="left"
    button vendor=0x06f7 product=0x0001 src=13 target=kbd button="right"
    
    button vendor=0x06f7 product=0x0001 src=6 target=kbd button="y"
    button vendor=0x06f7 product=0x0001 src=7 target=kbd button="n"
    
    button vendor=0x06f7 product=0x0001 src=4 target=kbd button="y"
    button vendor=0x06f7 product=0x0001 src=1 target=kbd button="space"
    button vendor=0x06f7 product=0x0001 src=8 target=kbd button="enter"
    
    button vendor=0x06f7 product=0x0001 src=9 target=kbd button="esc" 
    
    axis vendor=0x06f7 product=0x0001 src=0 target=mouse axis=0
    axis vendor=0x06f7 product=0x0001 src=1 target=mouse axis=1
    button vendor=0x06f7 product=0x0001 src=5 target=mouse button=0
    button vendor=0x06f7 product=0x0001 src=2 target=mouse button=1

    I’m wondering if some process is conflicting. I tried my brother’s N64 controller as well, and it’s the same behavior. I even made a Kodi map with the same axis lines, and the cursor behaved the exact same way.

    #107448
    Profile photo of MRKane
    MRKane
    Participant

    Could this method be used with the likes of DosBox to map controller input to keyboard for all of those four player games where we use to be clustered around one keyboard? 😀

    There's always one.

    #107457
    Profile photo of dudleydes
    dudleydes
    Participant

    @jonnygall

    I think I may know what you are referring to. In Kodi, it is possible to remove the mouse pointer by going to System > Settings > System > Input Devices and unchecking the Enable Mouse and touch screen support. After doing this, when you launch Kodi, the mouse pointer will appear momentarily, then disappear and you will see the Kodi logo.

    I have not found a way to do the same with lbreakout2. I don’t find it a problem as the mouse pointer disappears as soon as I press fire. You could contact the developer.

    @mrkane

    Yes, you can use the Linux Joystick Mapper program to map DOS games. I mapped mouse and keyboard controls to my PS3 controller for Ultima Underworld: Stygian Abyss. Before you try, please check your post on mapping multiple controllers in DOSBox as I have posted a link that may be helpful.

    #107485
    Profile photo of MRKane
    MRKane
    Participant

    Saying it here also: Thanks a heap for that dudelydes!

    There's always one.

    #107848
    Profile photo of MRKane
    MRKane
    Participant

    Right, finally had the time to sit down and try this and just want to say thanks so much for writing this guide! I’m still having a little trouble getting the buttons sorted out, and don’t seem to have any success myself with the axis stuff either.

    But again: THANK YOU!! I’m a total noob and well on the way!

    There's always one.

    #110149
    Profile photo of hypersonic
    hypersonic
    Participant

    This looked so easy on paper…

    I’m trying to set up a buffalo 8 axis snes style pad in kodi using the following but nothing works.

    # SNES Pad mapper file for Kodi
    
    # Navigation
    # D-pad to navigate; X to select and circle to go to previous menu
    axis vendor=0x054c product=0x0268 src=-1 target=kbd button="up"
    axis vendor=0x054c product=0x0268 src=-0 target=kbd button="right"
    axis vendor=0x054c product=0x0268 src=1 target=kbd button="down"
    axis vendor=0x054c product=0x0268 src=0 target=kbd button="left"
    
    button vendor=0x054c product=0x0268 src=1 target=kbd button="enter"
    button vendor=0x054c product=0x0268 src=0 target=kbd button="esc"
    
    # Triangle to bring up conextual menu
    button vendor=0x054c product=0x0268 src=2 target=kbd button="c"
    
    # Play Media
    # R1 to play/pause and L1 to stop
    button vendor=0x054c product=0x0268 src=4 target=kbd button="space"
    button vendor=0x054c product=0x0268 src=5 target=kbd button="x"
    
    # Exit Kodi by pressing Select and Start
    button vendor=0x054c product=0x0268 src=6 target=kbd button="leftctrl"
    button vendor=0x054c product=0x0268 src=7 target=kbd button="end"

    FWIW when i run jstest, i have names for my joypad buttons like ‘trigger’ or ‘thumbbtn’. Should i be using these or just the numbers as displayed in the testing lines at the bottom?

    What seems to be causing the problem is that the d-pad shows as an x and y axis, whereas it’d be a lot easier if it showed as 4 separate buttons.

    • This reply was modified 1 year, 5 months ago by Profile photo of hypersonic hypersonic.
    • This reply was modified 1 year, 5 months ago by Profile photo of hypersonic hypersonic.
    #110252
    Profile photo of dudleydes
    dudleydes
    Participant

    I’ve noticed you have the vendor and product identifiers for a PS3 controller in your mapper file. You need the identifiers for your SNES pad which you can find by running the command:

    cat /proc/bus/input/devices

    AFAIK, the arrow keys cannot be mapped to the axes. You could try mapping the mouse to the axes, which I have done for a number of mouse-driven DOS games. The lines to add would look like below:

    axis vendor=0xXXXX product=0xYYYY src=0 target=mouse axis=0
    axis vendor=0xXXXX product=0xYYYY src=1 target=mouse axis=1

    where XXXX is the vendor code for your SNES controller and YYYY the product code.

    #110278
    Profile photo of hypersonic
    hypersonic
    Participant

    You know, the ps3 product/vendor codes might be what’s wrong with my setup – i recall that i just copied your file and changed the buttons to suit.

    It never occurred to me that i’d have to change the ids too :$

    Let’s see if i can select +tive and -tive axis and map them to kbd keys

    • This reply was modified 1 year, 5 months ago by Profile photo of hypersonic hypersonic.
    #110283
    Profile photo of hypersonic
    hypersonic
    Participant

    Damn

    It doesn’t like the +tive and -tive axis lines and when i set the axes to mouse axes, it shows some promising lines in the console before loading kodi but doesn’t give me a mouse pointer.

    Also none of the controller buttons work, i’m wondering if i need to sort out a usb keyboard to go in and turn on the mouse pointer in kodi settings to make this work.

    #113115
    Profile photo of Omnija
    Omnija
    Participant

    Any idea on how to set up an xbox 360 controller when the vendor and product ID comes out as 0000 after using cat /proc/bus/input/devices

    also tried lsusb but it didn’t seem to map anything?

    #113130
    Profile photo of shades42
    shades42
    Participant

    I have tried this but seem to be stuck somewhere..

    output for joystick

    pi@retropie ~ $ cat /proc/bus/input/devices
    I: Bus=0003 Vendor=11c0 Product=5500 Version=0111
    N: Name="Tronsmart"
    P: Phys=usb-3f980000.usb-1.4/input0
    S: Sysfs=/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:11C0:5500.0001/input/input0
    U: Uniq=
    H: Handlers=js0 event0
    B: PROP=0
    B: EV=1b
    B: KEY=fff0000 0 0 0 0 0 0 0 0 0
    B: ABS=30027
    B: MSC=10

    I installed the package into :

    /home/pi/MyJoy

    my kodi.sh

    #!/bin/bash
    sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map &
    /opt/retropie/supplementary/runcommand/runcommand.sh 0 "kodi-standalone" "kodi"
    sudo killall loadmap
    sleep 1

    my kodi.map

    # Navigation
    # D-pad to navigate; X to select and circle to go to previous menu
    #axis  vendor=0x11c0 product=0x5500 src=5 target=kbd button="up"
    #axis vendor=0x11c0 product=0x5500 src=4 target=kbd button="right"
    #axis vendor=0x11c0 product=0x5500 src=5 target=kbd button="down"
    #axis vendor=0x11c0 product=0x5500 src=4 target=kbd button="left"
    
    button vendor=0x11c0 product=0x5500 src=2 target=kbd button="enter"
    button vendor=0x11c0 product=0x5500 src=1 target=kbd button="esc"
    
    # Triangle to bring up conextual menu
    button vendor=0x11c0 product=0x5500 src=0 target=kbd button="c"
    
    # Play Media
    # R1 to play/pause and L1 to stop
    button vendor=0x11c0 product=0x5500 src=11 target=kbd button="space"
    button vendor=0x11c0 product=0x5500 src=10 target=kbd button="x"
    
    # Exit Kodi by pressing Select and Start
    button vendor=0x11c0 product=0x5500 src=9 target=kbd button="leftctrl"
    button vendor=0x11c0 product=0x5500 src=8 target=kbd button="end"

    The reason the axis are commented out is because I was just testing to see if any buttons would work. I did get the “failed to grab device/failed to lock device messages.” with or without the axis in the .map file, but nothing would work.

    I did notice that once I was loaded into Kodi, the jstest would no longer register any of my joystick presses/movements. Could it be that I am losing my joystick when Kodi loads and that is why I am not registering anything within Kodi?

    When I do exit Kodi via the keyboard my joystick functionality comes back for ES, so I assume it has something to do with the loadmap

    • This reply was modified 1 year, 3 months ago by Profile photo of shades42 shades42.
    #113140
    Profile photo of shades42
    shades42
    Participant

    The Tronsmart has the option of switching which type of “joystick” it is, I tried it as an xbox 360 controller and the vendor and product #’s changed when I re ran the cat /proc/bus/input/devices

    so I tried that as well and I get nothing in Kodi, I’ve re read a few times and hunted around on the googles and can’t figure out what is wrong.

    Any help muchly appreciated

    #113158
    Profile photo of dudleydes
    dudleydes
    Participant

    @omnija

    You could try entering 0000 as your product code in your mapper file. Alternatively, you could use xboxdrv. Instructions below:

    https://www.reddit.com/r/RetroPie/comments/3mcf4y/kodi_with_xbox_360_controller/

    @shades42

    Have you tried running the loadmap program from a terminal on the pi? You should see key presses written to the terminal (you may want to change the key presses to letters rather than esc/ctrl for this).

    Alternatively, you can use your controller as a xbox 360 controller and try the link above.

    #113192
    Profile photo of shades42
    shades42
    Participant

    @dudleydues

    Hey man appreciate you taking the time to respond, half the fun for me is fighting with stuff to get it to work when I can’t but this is a little different because all of it is so new.

    I putty’d in with just the pi/raspberry credentials.

    
    
    pi@retropie /dev/input $ sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map
    0 joysticks.
    Found device Tronsmart (vendor=0x11c0, product=0x5500)
    Found device JOYMAP Code Device (vendor=0x00ff, product=0x0000)
    10 button assignments.
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    Failed to grab device: Device or resource busy
    Failed to lock device with vendor=0x11c0, product=0x5500. Continuing anyway...
    0 axes assignments.
    

    I do not know if it states “0 joysticks” is normal or not but that is what I see when trying to just run the map ( assuming I did that right lol ) and nothing on the screen when I press the buttons in a putty window.

    I’ll report back when I try it as an xbox controller via the link you provided, thanks again!

    #113196
    Profile photo of dudleydes
    dudleydes
    Participant

    You need to run the loadmap program from a terminal on the pi itself. I found that I didn’t see any key presses when I tried in a SSH session.

    #113205
    Profile photo of shades42
    shades42
    Participant

    Hey dudleydes,

    With the link you provided I was able to get joystick control in kodi no problems, but once I leave kodi a few things happen.

    #1. The joystick no longer works
    #2. If I quit ES afterwards to get to the terminal screen its just black and eventually goes back to ES. If I hit a key while its black it just stays black. I already upgraded to Kodi 15.2

    When I run

    sudo /home/pi/MyJoy/loadmap /home/pi/MyJoy/kodi.map

    from the terminal I get the same output I listed above ( with the inclusion of the xbox gamepad from trying the other link ) but again nothing being written on the screen.

    I also changed all the button presses to letters in the map file

    button vendor=0x11c0 product=0x5500 src=2 target=kbd button="a"
    button vendor=0x11c0 product=0x5500 src=1 target=kbd button="b"
    
    # Triangle to bring up conextual menu
    button vendor=0x11c0 product=0x5500 src=0 target=kbd button="c"
    
    # Play Media
    # R1 to play/pause and L1 to stop
    #utton vendor=0x11c0 product=0x5500 src=11 target=kbd button="d"
    #utton vendor=0x11c0 product=0x5500 src=10 target=kbd button="e"
    
    # Exit Kodi by pressing Select and Start
    button vendor=0x11c0 product=0x5500 src=9 target=kbd button="f"
    button vendor=0x11c0 product=0x5500 src=8 target=kbd button="g"
    • This reply was modified 1 year, 3 months ago by Profile photo of shades42 shades42. Reason: new button maps
    #113210
    Profile photo of Omnija
    Omnija
    Participant

    @dudleydes I actually tried that before this one, after quitting kodi it would screw up my ES controller settings. I also tried 0000 and did lsusb using the logic3 vender/product id and it still didn’t work

    #113240
    Profile photo of shades42
    shades42
    Participant

    @dudleydes I noticed with the link you provided there is a type for the permissions

    Changing uInput Device Permission

    sudo groupdadd -f uinput there is an extra d groupdadd

    once you remove it and put

    sudo groupadd -f uinput it works and if you are C/P’ing the

    KERNEL==”uinput”, GROUP=”uinput”, MODE:=”0660″ you will need to change the quotes.

    I can run the loadmap without the sudo now ( i worked on this incase that was the issue ) but still no button presses.

    I am wondering if installing the Virtual Gamepad is messing some of this up.

    Do you have it installed? if not I need to figure out how to uninstall it

    #113629
    Profile photo of shades42
    shades42
    Participant

    I think I am going to have to toss in the towel with my controller and this option, I’ve go so far as fresh install and only the joymap and never get anything registering.

    It was an exciting possibility and fun messing with it but no luck and out of ideas 🙂

    Thanks though and thanks for the direction.

    #113640
    Profile photo of shades42
    shades42
    Participant

    I lied I can’t toss the towel in lol…

    I grabbed a wired xbox controller and hooked that up and tried giving it ago and I couldn’t register any button presses with that either..

    Any suggestions are welcome, it isn’t for KODI so much anymore its wanting to map key presses to the joystick for other things now so I need to figure out what is wrong.

    Thanks in advance

    #113652
    Profile photo of dudleydes
    dudleydes
    Participant

    @shades42

    Thanks for tidying up the changing uInput device permission issue. It was the quotes in the udev rule that was causing the problem.

    I’m sorry to hear that you’ve had no luck using the loadmap program with your controllers. All I can suggest is that you try the attached binary that works for me.

    Attachments:
    1. loadmap.zip
    #113668
    Profile photo of shades42
    shades42
    Participant

    Thanks for the effort, first did a comparison yours and mine are the same, tried it anyway still no success.

    Seems lot of people use this option, even read some SteamOS threads about people using it successfully, so it has to be me somewhere some way 🙂

    At least this endeavor cleaned things up a little for you, and I learned a bunch of stuff along the way. Now I am trying to write my own code to see if I can get something working.

    #113818
    Profile photo of shades42
    shades42
    Participant

    Just an update on this for anyone else looking and reading.

    If I run jstest in putty on another system, and presses buttons while Kodi it loading, as soon as it is up and running, all my buttons stop registering. I have tried this with both wheezy and jessie running Kodi 15.2 on fresh installs.

    As soon as Kodi exits, my buttons start function again (before it goes back in ES).

    I wish I thought of this before, because I wrote/stole/borrowed/modified some code that will take inputs from js0 (buttons and axis) and map them to key presses and they show up in the terminal window of the pi, but its useless if Kodi “kills” the joystick 🙂

    #114071
    Profile photo of Computer Ninja
    Computer Ninja
    Participant

    Any updates on getting a USB Gamepad (like my Logitech F310) working with Kodi?

    #117421
    Profile photo of noratio
    noratio
    Participant

    Alright @shades42, after hours of having the same issue as you, I finally found out the problem.. it’s easy you will see.

    Just unplug your keyboard

    0- Turn off your PI
    1- Make sure you only have your PS3 or Xbox controller plugged in with instructions from @dudleydes
    2- Start Kodi and enjoy!!

    Hope that works for you. It looks like the cause of the problem the mapping in changed because of what ever Raspbian detected for your keyboard. So the region changed for the mapping. I was using a Apple Keyboard, and with another keyboard when I was pressing buttons it was different characters. As soon I rebooted without a keyboard, everything worked and man, it’s now a complete solution that Retropie/Emulationstation/Kodi. I must say that I have cloned my SD card and it will be some Christmas gift next year.

    Cheers!

Viewing 28 posts - 1 through 28 (of 28 total)

Forums are currently read only - please visit the new RetroPie forums at https://retropie.org.uk/forums/

Skip to toolbar