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

  • Pi Model or other hardware: RasPi 4
    Power Supply used: Official PSU
    RetroPie Version Used (eg 3.6, 3.8.1, 4.1 - do not write latest):
    USB Devices connected: USB Encoder
    Emulator: All (global keys across emulators)
    How to replicate the problem: Have USB encoder with buttons and attempt my assign button to "escape" key

    Hi, just wanted to start by saying everything is working fine for the most part, I have 3 different controllers working and mapped nicely and emulators are running flawlessly.

    My issue: I like having the escape key be the global exit button but I would also like to make one of my USB encoder buttons imitate the escape key similar to how in emulation station you map a controller to the various inputs.

    I went into the /opt/retropie/configs/all/retroarch.cfg file and found the line for exiting with escape and I can pull the controller info/id and input value from the emulationstation .cfg file or through jstest.

    I'm not sure how/where to write "controller 1" input "x" = "escape".

    One item to note is that the encoder is only being used for function keys and all other actions and emulator inputs are through various controllers so it is important that I can specify the specific controller and its input not just a general input(0) = escape in the event there's a shared input number with a different named/id controller.

    Thanks in advance.

  • Global Moderator

    If you enabled the hotkey for the controller/encoder, then exiting will have to be done through the Hotkey + Start combination, it will not work with just a single button.
    Note that the input settings in retroarch.cfg apply mainly to keyboard based controllers, if your encoder is detected as gamepad device, a controller configuration will be created in /opt/retropie/configs/all/retroarch-joypads after you do the input config in EmulationStation.


  • I only did the input config in EmulationStation to find out the input value for the encoder slot before I read about how jstest worked. I don't actually need the encoder to act as a controller.

    Can a gamepad device be manually configured to act as a keyboard based controller? If that isn't possible, is there a means of editing the controller config file you mentioned to map a button to "escape" instead of input "1" for example? I only plan to have 2 buttons through the encoder, an exit emulator and a shutdown script button so I want to avoid the Hotkey + Start solution if at all possible.

  • Global Moderator

    @bpm009 said in USB Encoder Mapping:

    Can a gamepad device be manually configured to act as a keyboard based controller?

    No.

    If that isn't possible, is there a means of editing the controller config file you mentioned to map a button to "escape" instead of input "1" for example?

    escape is just the default keyboard binding for exiting the emulator in RetroArch, you need to set input_exit_emulator - for a keyboard - or the input_exit_emulator_btn- for a gamepad.

    I only plan to have 2 buttons through the encoder, an exit emulator and a shutdown script button so I want to avoid the Hotkey + Start solution if at all possible.

    I'm not sure if that's possible - in RetroArch only P1 has access to the hotkey commands, so if you're looking for a gamepad/keyboard to work only for exiting the emulator, then I don't think this will work with just input configuration.

    Someone posted something similarly yesterday - https://retropie.org.uk/forum/topic/25538/ - see if it works for you to use an external script with the triggerhappy service.


  • escape is just the default keyboard binding for exiting the emulator in RetroArch, you need to set input_exit_emulator - for a keyboard - or the input_exit_emulator_btn- for a gamepad.

    Is input_exit_emulator_btn in all/retroarch.cfg part of the P1 specific hotkey commands you mentioned? If I place the encoder as a permanent P4 and find a way to have the button input value be a number not used by the other controllers could I then set input_exit_emulator_btn = "x" where x is that unique button value?

    I will take a look at that article, thanks for the reference. I see they OP used a keyboard encoder, is that important in making the setup work?

  • Global Moderator

    @bpm009 said in USB Encoder Mapping:

    Is input_exit_emulator_btn in all/retroarch.cfg part of the P1 specific hotkey commands you mentioned? If I place the encoder as a permanent P4 and find a way to have the button input value be a number not used by the other controllers could I then set input_exit_emulator_btn = "x" where x is that unique button value?

    I don't think so. If you've enabled the hotkey for P1, then the commands would need a hotkey to be registered.

    I will take a look at that article, thanks for the reference. I see they OP used a keyboard encoder, is that important in making the setup work?

    No, if you already have a script that interprets the inputs from a certain controller/gamepad/keyboard, etc., then you can skip over using the triggerhappy part and attach the RetroArch exit script to your script.


  • I think I'm making some progress, I came across another thread using jslisten to run a script on button press. I think combining this with dedicating the "1 button controller" as P4 always I should be able to create a workaround. Where do I find the RetroArch exit script so I can use it in my script? If this works I'll post the entire solution in one reply.

  • Global Moderator

    @bpm009 said in USB Encoder Mapping:

    Where do I find the RetroArch exit script so I can use it in my script? If this works I'll post the entire solution in one reply.

    Look in the topic that I linked.


  • I see that the script has to be created. In the topic they require a "Pause" command which looks to be "Pause_Toggle". What is the command for "Exit Emulator"?


  • Just as a test I also tried the setup you mentioned in the linked post and I also was unable to get P to pause the game. I did check with systemctl that the service was running on startup.

  • Global Moderator

    @bpm009 said in USB Encoder Mapping:

    I see that the script has to be created. In the topic they require a "Pause" command which looks to be "Pause_Toggle". What is the command for "Exit Emulator"?

    The command is QUIT (full list of commands is here).

    Just as a test I also tried the setup you mentioned in the linked post and I also was unable to get P to pause the game

    Does it work if you run the script manually ?


  • Run the pause script manually? I know that I can return to emulation station through the terminal but can I start a game in an emulator, enter the terminal to run the script and return back to the game? If so I'm not sure on the process sorry. I'm willing to give it a shot if I can find out how.

  • Global Moderator

    @bpm009 You can use SSH to run commands on the PI, without needing a keyboard.


  • Ok, using SSH I ran the script and it did not send a pause command to the game running.

    Just to clarify, I went into the SSH terminal to the directory and entered ./pause-ra.sh which I believe is the correct method.

    I used the code you explained in the other post shown below for the pause-ra.sh script.

    #!/bin/bash
    echo -n "PAUSE_TOGGLE" | nc -d -u -w1 127.0.0.1 55355
    
    
  • Global Moderator

    @bpm009 OK, did you modify the retroarch.cfg file to enable network input, like explained in the post ?


  • Yes, I added the following line to the end of the retroarch.cfg file.

    network_cmd_enable = "true"
    
  • Global Moderator

    @bpm009 said in USB Encoder Mapping:

    #!/bin/bash
    echo -n "PAUSE_TOGGLE" | nc -d -u -w1 127.0.0.1 55355

    Modify the script to

    #!/bin/bash
    echo -n "PAUSE_TOGGLE" | nc -u -w1 127.0.0.1 55355
    

    I think I added an extra parameter that doesn't do what it should.


  • Still no luck when running the script directly.

  • Global Moderator

    Works for me - are you sure you're running a RetroArch emulator ? What game are you starting and what emulator appears in the launch command message ?


  • Not 100% sure.I am running super mario kart and the SNES9X emulator.

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.