RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login
    Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

    Swap x and y in ES?

    Scheduled Pinned Locked Moved Help and Support
    button swap
    4 Posts 4 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • quicksilverQ
      quicksilver
      last edited by

      Is there a way to swap x and y in just emulation station? I have done it for a and b but would like to swap x and y too.

      1 Reply Last reply Reply Quote 1
      • C
        ChuckyP
        last edited by ChuckyP

        I would love to see this added to the setup script as well. When using XBOX pads the official configuration leaves the X & Y buttons swapped when using favorites and random game select.

        You can reconfigure the RetroArch button mapping so emulation station sees it correctly. And keep the game cores correct.

        Myself I just map the controllers through the emulation station prompt “correctly” with the proper button configuration so A is A and so on. And then change each core so the buttons map correctly per system. That’s quite a process but once the configs are done you can just drag and drop from a backup obviously.

        1 Reply Last reply Reply Quote 0
        • R
          ReenigneArcher
          last edited by ReenigneArcher

          I know this post if fairly old but here is how to swap a/b & x/y together. Replace the contents of the file: /opt/retropie/supplementary/emulationstation/scrips/configscripts/emulationstation.sh with the code below. Then enable the swap a_b option as normal. Finally reconfigure you gamepad.

          If you want to know how it works so you can customize it further (i.e. maybe swap only x/y, or swap some other buttons) this is a brief explanation. When you turn the swap a_b option on it changes the value of "es_swap_a_b" from 0 to 1 in /opt/retropie/configs/all/autoconf.cfg. Then the script below checks if that value is 0 or 1 for a, b, x, and y (the original checks only for a and b). If the value is 0 it leaves them as is. If the value is 1 it assigns the other value per the definition in the script below. I am not an expert programmer otherwise I would try to add it as a separate option in the retropie configuration tool and have it write a separate variable for x and y swap. In any event this works well for me using Xbox controllers.

          #!/usr/bin/env bash
          
          # This file is part of The RetroPie Project
          #
          # The RetroPie Project is the legal property of its developers, whose names are
          # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
          #
          # See the LICENSE.md file at the top-level directory of this distribution and
          # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
          #
          
          function onstart_emulationstation_joystick() {
              local es_conf="$home/.emulationstation/es_input.cfg"
          
              mkdir -p "$home/.emulationstation"
          
              if [[ ! -f "$es_conf" ]]; then
                  echo "<inputList />" >"$es_conf"
              else
                  cp "$es_conf" "$es_conf.bak"
              fi
          
              # look for existing inputConfig in config by GUID
              if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"])" "$es_conf") -eq 0 ]]; then
                  # if not found by GUID, look for inputConfig with deviceName only
                  if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceName=\"$DEVICE_NAME\"][not(@deviceGUID)])" "$es_conf") -eq 0 ]]; then
                      # insert new inputConfig entry
                      xmlstarlet ed -L -s "/inputList" -t elem -n newInputConfig -v "" \
                          -i //newInputConfig -t attr -n "type" -v "$DEVICE_TYPE" \
                          -i //newInputConfig -t attr -n "deviceName" -v "$DEVICE_NAME" \
                          -i //newInputConfig -t attr -n "deviceGUID" -v "$DEVICE_GUID" \
                          -r //newInputConfig -v inputConfig \
                          "$es_conf"
                  else
                      # add deviceGUID to inputConfig
                      xmlstarlet ed -L \
                          -i "/inputList/inputConfig[@deviceName=\"$DEVICE_NAME\"]" -t attr -n "deviceGUID" -v "$DEVICE_GUID" \
                          "$es_conf"
                  fi
              fi
          }
          
          function map_emulationstation_joystick() {
              local input_name="$1"
              local input_type="$2"
              local input_id="$3"
              local input_value="$4"
          
              local key
              case "$input_name" in
                  leftbottom|leftshoulder)
                      key="pageup"
                      ;;
                  rightbottom|rightshoulder)
                      key="pagedown"
                      ;;
                  up|right|down|left|start|select|leftanalogup|leftanalogright|leftanalogdown|leftanalogleft|rightanalogup|rightanalogright|rightanalogdown|rightanalogleft)
                      key="$input_name"
                      ;;
                  a)
                      key="$input_name"
                      getAutoConf es_swap_a_b && key="b"
                      ;;
                  b)
                      key="$input_name"
                      getAutoConf es_swap_a_b && key="a"
                      ;;
                  x)
                      key="$input_name"
                      getAutoConf es_swap_a_b && key="y"
                      ;;
                  y)
                      key="$input_name"
                      getAutoConf es_swap_a_b && key="x"
                      ;;
                  *)
                      return
                      ;;
              esac
              local es_conf="$home/.emulationstation/es_input.cfg"
          
              # add or update element
              if [[ $(xmlstarlet sel -t -v "count(/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"])" "$es_conf") -eq 0 ]]; then
                  xmlstarlet ed -L -s "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]" -t elem -n newinput -v "" \
                      -i //newinput -t attr -n "name" -v "$key" \
                      -i //newinput -t attr -n "type" -v "$input_type" \
                      -i //newinput -t attr -n "id" -v "$input_id" \
                      -i //newinput -t attr -n "value" -v "$input_value" \
                      -r //newinput -v input \
                      "$es_conf"
              else  # if device already exists, update it
                  xmlstarlet ed -L \
                      -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@type" -v "$input_type" \
                      -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@id" -v "$input_id" \
                      -u "/inputList/inputConfig[@deviceGUID=\"$DEVICE_GUID\"]/input[@name=\"$key\"]/@value" -v "$input_value" \
                      "$es_conf"
              fi
          }
          
          function onstart_emulationstation_keyboard() {
              onstart_emulationstation_joystick "$@"
          }
          
          function map_emulationstation_keyboard() {
              map_emulationstation_joystick "$@"
          }
          
          function onstart_emulationstation_cec() {
              onstart_emulationstation_joystick "$@"
          }
          
          function map_emulationstation_cec() {
              map_emulationstation_joystick "$@"
          }
          

          Hope it helps.

          1 Reply Last reply Reply Quote 0
          • vbsV
            vbs
            last edited by

            @ReenigneArcher
            Thanks mate, I was always annoyed by this!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            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.