RetroArch icon indicating copy to clipboard operation
RetroArch copied to clipboard

Mouse index changes between boots

Open roadriverrail opened this issue 8 years ago • 37 comments

I'm using RetroArch as part of a RetroPie settup. Everything works wonderfully with one small exception-- my machine includes both a trackball and a spinner. Both devices enumerate as mice over USB and appear as devices with /dev/input/eventXX numbers.

I can follow the steps for setting up my trackball as the player default in games, but that configuration will ultimately fail after enough reboots (often, just one reboot) because the /dev/input/eventXX numbers are assigned depending on what order these mice enumerate in. To make the trackball work, I basically have to change the input_player1_mouse_index every time it ends up with a different eventXX value.

As far as I can tell, there's no way for me to force the assignment of a particular eventXX value, but it looks like there are other ways to tell the trackball from the spinner. One is /dev/input/by-id, which symlinks to the event files. I think another would be using udev to make symlinks. In either case, though, it looks like RetroArch would need to be modified to accept a string rather than just an index number. I've only lightly skimmed your udev mouse code.

Is there a way of handling this that I've missed? If there isn't, is there any interest from the folks in working on this? I'm plenty handy at C but not as familiar with RetroArch, so I'd probably want a few conversations with someone to scope out the work and make sure I'm doing this the right way.

roadriverrail avatar Nov 23 '18 22:11 roadriverrail

@roadriverrail Does this happen when only using RetroArch without RetroPie? I would suspect a general OS issue before RetroArch as the order of devices is determined by the OS and not RetroArch.

orbea avatar Jan 01 '19 03:01 orbea

@orbea, perhaps I didn't explain it fully. The order of USB device enumeration and driver initialization at boot time is not fully deterministic, so the current index system is not guaranteed to work from one boot to the next if you have, say, multiple mouse devices; my machine has both a trackball and a spinner, and so I have to fix up the mouse_index values after I boot up. It'd be more reliable to use something that identifies the device, like it's reported model name or it's VID/PID tuple.

roadriverrail avatar Jan 01 '19 03:01 roadriverrail

Yes, I understood. I think the best solution would be to fix this race condition in the OS. Of course this is easier said than done.

There may be room to work around this in RetroArch, but it would not be easy and may have its own caveats.

Personally the devices are fully deterministic here, but my setup is pretty different than yours.

orbea avatar Jan 01 '19 03:01 orbea

I disagree that the "best" solution is to lock down the ordering of USB devices in Linux. It's not just easier said than done. My understanding, which may be wrong, is that doing so is fundamentally unsupported as a matter of architecture.

I've actually already started slinging together some code to add support for an "input_mouse_model" array in the configuration/settings and in adding a clause to udev_get_mouse() to match the "input_mouse_model" against the ID_MODEL udev property. It all looks okay and compiles, but I haven't moved it over to my game machine to test it yet. Is there some reason you'd not expect a scheme like this to work? You seem really hesitant on this front, and I suspect that's with cause.

roadriverrail avatar Jan 01 '19 17:01 roadriverrail

By all means if you or someone else can come up with a good solution within RA that is great! I just think that there are probably other programs than RetroArch that would benefit from a broader fix in the OS.

orbea avatar Jan 01 '19 17:01 orbea

Ah. Understood. Again, I may be off-base on this, but I think that RA is a bit of an outlier in its entire reliance on the event input number to identify the peripheral. It's brittle against all sorts of changes on peripherals. For example, if you were to unplug and re-plug your USB devices, then the event device numbers will be different. From what little I've played with the input event device space, in my implementing Android firmware, it's more common to probe the devices, find some meaningful identifier (model, VID:PID, etc), and use that. That way, you know you're talking to the right device.

roadriverrail avatar Jan 01 '19 17:01 roadriverrail

The solution should be bind devices on button press, not before, that's all.

andres-asm avatar Jan 01 '19 20:01 andres-asm

@fr500 I'm not following. Neither my trackball nor spinner have buttons, and as far as I know, the binding is governed by the playerX_mouse_index fields in the configuration files.

roadriverrail avatar Jan 01 '19 21:01 roadriverrail

Well most mice do :P but in this case it would be on event..

Thing is this issue has existed forever with controllers.

We currently bind the devices on enumeration, so if you have 10 gamepads it assigns them a port id based on the enumeration order given by the underlying operating system.

That enumeration as you mentioned before is volatile. So a better strategy would be to enumerate devices and set them all as pending for binding, then when one of those devices has some input (gamepad button pressed, analog tilted, mouse moved) map them to the next available port.

andres-asm avatar Jan 01 '19 21:01 andres-asm

Ah, I'm understanding what you're suggesting, and it's a really neat low-touch idea. Does RA already open up a handle to all event devices and passively listen to all of them, filtering out only the ones with mapped ports?

roadriverrail avatar Jan 01 '19 21:01 roadriverrail

I looked at this mouse index business two years ago as I was hitting the same problem with my retroarch cabinet. Trackball and spinner devices would switch randomly at each reboot. I suspect this code hasn't changed since. I'll dump my thinking about this anyways.

Even if I find a way to "fix" the number at the OS level (linux /dev numbers), retroarch completely disregards the OS's index and does its own "enumeration". As for Windows, the OS actually do attempt to detects where the device is connected and "knows" it's the same one (for the purpose of loading and initializing settings and drivers). Again, that won't guarantee the "ordering" Retroarch will receive the notifications about a device because, again, it has nothing to do with an "order based on time".

You are just lucky if you get them in the same order. It's not a OS problem at all. Rather a misinterpretation on how OSes behave and then wrongfully "shovels" the problem to the OS side.

It seems they (retroarch) don't really think it's a problem because they are under the assumption that in all cases the user will interactively "click a button" while performing a setup to "select a controller". Unfortunately, retroarch is used in other use cases and sometimes these are not controllers that you just connect "ad hoc" and perform a "setup" just before playing a game. These are bolted devices on a cabinet where other people (kids or guests) that are not even allowed to do any setup will attempt to power up the cabinet and play games. The player 1 spinner device is always going to be the same physical spinner connected to the same port. There is no reason that it suddenly gets assigned player 2.

Maybe we could look at MAME for inspiration? They have a fix for this that they coined mapdevice. https://docs.mamedev.org/advanced/devicemap.html
You can essentially map how the virtual devices are mapped to devices using a special "string" matching the raw identifier. We can keep the index numbers as is but then we could have an extra configuration on how these numbers gets mapped. Essentially it would "reserve" index numbers that are "configured" and as you get new devices if there is a match and the number if not already taken, we assign it the configured number else you assign a new sequential number like before.

Another enhancement would be to wait until there is no more device notifications at startup (with a configurable timeout) and then perform a full enumeration (with some fixed ordering/sorting). That might actually give a little more stable indexes with zero configuration (again, not always). After that, the same logic would apply with new devices coming in afterwards.

If we can get some sort of agreement on how to do this, maybe then we can get a green light to start working on a PR? Any combination of mouse-like devices (lightguns, spinners, trackballs and real mouse) are immediate candidate but also any other USB devices could also benefit this. As @fr500 pointed out: "this issue has existed forever with controllers." Well, maybe we could fix that at the same time, a "forever issue" doesn't make it less annoying...

popbee avatar Jun 07 '21 03:06 popbee

@popbee did you gain any traction anywhere for this issue/enhancement?

thatman84 avatar Dec 11 '21 21:12 thatman84

No traction. Let's ask again these guys: @orbea @fr500

By all means if you or someone else can come up with a good solution within RA that is great! I just think that there are probably other programs than RetroArch that would benefit from a broader fix in the OS.

The OS enumeration order (appearance order) cannot be fixed at the OS level because it's by design. @roadriverrail was being very kind and tried to explain it but I think you guys don't get it and are still stuck on the "waiting on a button" solution. BTW, the RA code looks at the "appearance order" and NOT the OS enumeration order. There is a distinction! MAME definitely solved the problem with mapdevice. There are multiple solutions that can minimize the work and the risk. We can keep the index numbers as before but just influence how it gets mapped a little. That's all! Why can't we decide on something? You have people that are willing to help here.

"Waiting for an input event" is NOT a good solution for fixed cabinets. You are asking the players (i.e. kids/guests) to re-configure the cabinet manually each time it re-boots!

If I invest time to make a PR, I don't want you guys to plain reject it just because you don't like the approach.

How should we proceed?

popbee avatar Dec 12 '21 05:12 popbee

This apparently isn't in the top list of things to update for the retroarch developers. In a nutshell:

I created a fix that works for me, hopefully it helps someone else out there too. If it does, please kindly let me know! All of this assumes you are using Windows with Retroarch in raw mode to support multiple mice (and possibly joysticks too). Python 3.7.4 must be installed prior (might also work with 2.x but haven't tested). I am re-using ControllerRemap.exe (this was created back in the day when Mame had the same shortcoming?) to find which devices are out there and their order. The accompanying remapIdentifiers.py python script updates the mouse and/or joystick indices on a user supplied list of retroarch config files. If the device is not found, it will set it to '-1' which seems to disable it. I also have a separate (optional) customization option that I found handy to disable lightgun crosshairs when a particular player was not enabled. More detailed instructions are included in the accompanying remapIdentifiers.ini file. I left some example configuration in the .ini to help illlustrate--obviously these will need to be removed prior to usage.

  1. Extract the zip files in a desired directory (typically within the retroarch folder)
  2. Update the remapIdentifiers.ini file with instructions included in the remapIdentiers.ini file
  3. Plug in desired equipment (mice, etc.), and use python to run the remapIdentiers.py script (many ways to accomplish this) prior to running retroarch.

That's it ! remapIdentifiers v0.0.zip

drlucid avatar Feb 11 '23 00:02 drlucid

For those who want their trackball, mouse, spinner, etc configured automatically, I just released Multi-Mouse MM 1.0.2 for Batocera v35 and later https://github.com/StarPlayrX/Multi-Mouse

No editing, smart programming, just install and play!

AgentiLoop avatar Mar 25 '23 03:03 AgentiLoop

@drlucid , you saved a lot of stuff with you python code thanks!!! i hope you read this message. for the mouses i fixed totally, but i have an issue with the joypads for example i have from the list: 'Gamecube Controller', ID=1" 'Gamecube Controller', ID=2"

now, i paste this in the right file ini for change, but the cfg file return "-1" so i tried few things: input_player1_joypad_index = ID=1 input_player2_joypad_index = ID=2 return = "-1"

input_player1_joypad_index = 'Gamecube Controller', ID=1" input_player2_joypad_index = 'Gamecube Controller', ID=2" return = "-1"

the only change that works is: input_player1_joypad_index = Gamecube Controller input_player2_joypad_index = Gamecube Controller

and here the problem in th cfg: input_player1_joypad_index = 9 input_player2_joypad_index = 9 in this way works but it have for all the players the same id in the cfg, and when i open retroarch gamecube controller is not set, other one is put on casually.

how i can specify in the remappingidentifier.ini the IDs? (ID=1 and ID=2)?

thanks!!

Shinlowneogetter avatar Aug 25 '23 19:08 Shinlowneogetter

when you type controllerremap.exe /list what do you see? for example

C:\Users\drlucid\eclipse-workspace\remap_tool>ControllerRemap.exe /list

ControllerRemap Utility v0.0.11.0 - For Mame (c) 2011 drventure Enterprises

Joystick Device List (Devices are in enumeration order) ...

No devices found.

Mouse Device List (Devices are in enumeration order) ...

  1. 'HID#VID_046D_PID_C52B_MI_01_Col01#8_532c6de_0_0000#'

End of list

On Fri, Aug 25, 2023 at 1:09 PM Shinlowneogetter @.***> wrote:

@drlucid https://github.com/drlucid , you saved a lot of stuff with you python code thanks!!! i hope you read this message. for the mouses i fixed totally, but i have an issue with the joypads for example i have from the list: 'Gamecube Controller', ID=1" 'Gamecube Controller', ID=2"

now, i paste this in the right file ini for change, but the cfg file return "-1" so i tried few things: input_player1_joypad_index = ID=1 input_player2_joypad_index = ID=2 return = "-1"

input_player1_joypad_index = 'Gamecube Controller', ID=1" input_player2_joypad_index = 'Gamecube Controller', ID=2" return = "-1"

the only change that works is: input_player1_joypad_index = Gamecube Controller input_player2_joypad_index = Gamecube Controller

and here the problem in th cfg: input_player1_joypad_index = 9 input_player2_joypad_index = 9 in this way works but it have for all the players the same id in the cfg, and when i open retroarch gamecube controller is not set, other one is put on casually.

how i can specify in the remappingidentifier.ini the IDs? (ID=1 and ID=2)?

thanks!!

— Reply to this email directly, view it on GitHub https://github.com/libretro/RetroArch/issues/7638#issuecomment-1693814173, or unsubscribe https://github.com/notifications/unsubscribe-auth/A52OIULMLJTK6PAARTYD3E3XXDZ53ANCNFSM4GGETPGA . You are receiving this because you were mentioned.Message ID: @.***>

drlucid avatar Aug 26 '23 00:08 drlucid

@drlucid Here is the problem, i have 4 gamecube controllers

from /list:

2023-08-26T09:00:43 ControllerRemap Utility v0.0.11.0 - For Mame (c) 2011 drventure Enterprises

2023-08-26T09:00:43 2023-08-26T09:00:43 Joystick Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'Controller (XBOX 360 For Windows)', ID=3 2023-08-26T09:00:43 2. 'Controller (XBOX 360 For Windows)', ID=2 2023-08-26T09:00:43 3. 'GameCube Controller Adapter', ID=12 2023-08-26T09:00:43 4. 'USB_Game12', ID=11 2023-08-26T09:00:43 5. 'GameCube Controller Adapter', ID=15 2023-08-26T09:00:43 6. 'GameCube Controller Adapter', ID=13 2023-08-26T09:00:43 7. 'GameCube Controller Adapter', ID=14 2023-08-26T09:00:43 8. 'JUYAO Dual Arcade', ID=0 2023-08-26T09:00:43 9. 'JUYAO Dual Arcade', ID=1 2023-08-26T09:00:43 2023-08-26T09:00:43 Mouse Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'HID#VID_0461_PID_4D15#7_3a9bae7e_0_0000#' 2023-08-26T09:00:43 2. 'HID#VID_0079_PID_1802_MI_01_Col01#9_1f1dbd06_0_0000#' 2023-08-26T09:00:43 3. 'HID#VID_0079_PID_1802_MI_01_Col01#8_a4751fc_0_0000#' 2023-08-26T09:00:43 4. 'HID#VID_0000_PID_3825#8_30bac947_1_0000#' 2023-08-26T09:00:43 5. 'HID#VID_0461_PID_4E35#8_292af9fc_0_0000#' 2023-08-26T09:00:43 6. 'HID#VID_0000_PID_3825#8_15447cba_2_0000#' 2023-08-26T09:00:43 7. 'HID#VID_046D_PID_C062#7_219e267b_1_0000#' 2023-08-26T09:00:43 2023-08-26T09:00:43 End of list

When i copy and paste in remappingcontrollers.ini , it don't works: input_player1_joypad_index = GameCube Controller Adapter, ID=12 input_player2_joypad_index = GameCube Controller Adapter, ID=15 input_player3_joypad_index = GameCube Controller Adapter, ID=13 input_player4_joypad_index = GameCube Controller Adapter, ID=14

in dolphin.cfg it return -1

if i copy and paste this in remappingcontrollers.ini: input_player1_joypad_index = GameCube Controller Adapter input_player2_joypad_index = GameCube Controller Adapter input_player3_joypad_index = GameCube Controller Adapter input_player4_joypad_index = GameCube Controller Adapter

it works for the file in dolphin-emu.cfg but in retroarch don't works input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9

cause in this way the problem is that all are positioned in 9

if i put manually in retroarch settings the 4 controllers temporary directly here the cfg: input_player1_joypad_index = 3 input_player2_joypad_index = 7 input_player3_joypad_index = 5 input_player4_joypad_index = 6

i need to specify the ID=12 for example and here i don't know how to do

Shinlowneogetter avatar Aug 26 '23 07:08 Shinlowneogetter

The problem is my original assumption was that the unique identifier would be encased in single quotes. For the HID devices it is, but for the game controllers just 'GameCube Controller Adapter' is what is encased in single quotes which is obviously not unique. It is a really simple fix.

Give this a try and tell me if it works, and I will update the zip file for future users.

On Sat, Aug 26, 2023 at 1:09 AM Shinlowneogetter @.***> wrote:

@drlucid https://github.com/drlucid Here is the problem, i have 4 gamecube controllers

2023-08-26T09:00:43 ControllerRemap Utility v0.0.11.0 - For Mame (c) 2011 drventure Enterprises

2023-08-26T09:00:43 2023-08-26T09:00:43 Joystick Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'Controller (XBOX 360 For Windows)', ID=3 2023-08-26T09:00:43 2. 'Controller (XBOX 360 For Windows)', ID=2 2023-08-26T09:00:43 3. 'GameCube Controller Adapter', ID=12 2023-08-26T09:00:43 4. 'USB_Game12', ID=11 2023-08-26T09:00:43 5. 'GameCube Controller Adapter', ID=15 2023-08-26T09:00:43 6. 'GameCube Controller Adapter', ID=13 2023-08-26T09:00:43 7. 'GameCube Controller Adapter', ID=14 2023-08-26T09:00:43 8. 'JUYAO Dual Arcade', ID=0 2023-08-26T09:00:43 9. 'JUYAO Dual Arcade', ID=1 2023-08-26T09:00:43 2023-08-26T09:00:43 Mouse Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'HID#VID_0461_PID_4D15#7_3a9bae7e_0_0000#' 2023-08-26T09:00:43 2. 'HID#VID_0079_PID_1802_MI_01_Col01#9_1f1dbd06_0_0000#' 2023-08-26T09:00:43 3. 'HID#VID_0079_PID_1802_MI_01_Col01#8_a4751fc_0_0000#' 2023-08-26T09:00:43 4. 'HID#VID_0000_PID_3825#8_30bac947_1_0000#' 2023-08-26T09:00:43 5. 'HID#VID_0461_PID_4E35#8_292af9fc_0_0000#' 2023-08-26T09:00:43 6. 'HID#VID_0000_PID_3825#8_15447cba_2_0000#' 2023-08-26T09:00:43 7. 'HID#VID_046D_PID_C062#7_219e267b_1_0000#' 2023-08-26T09:00:43 2023-08-26T09:00:43 End of list

When i copy and paste , it don't works: input_player1_joypad_index = GameCube Controller Adapter, ID=12 input_player2_joypad_index = GameCube Controller Adapter, ID=15 input_player3_joypad_index = GameCube Controller Adapter, ID=13 input_player4_joypad_index = GameCube Controller Adapter, ID=14

in dolphin.cfg it return -1

if i copy and paste this: input_player1_joypad_index = GameCube Controller Adapter input_player2_joypad_index = GameCube Controller Adapter input_player3_joypad_index = GameCube Controller Adapter input_player4_joypad_index = GameCube Controller Adapter

in dolphin-emu.cfg input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9

the problem is that all are positioned in 9

if i put manually in retroarch settings the 4 controllers temporary directly here the cfg: input_player1_joypad_index = 3 input_player2_joypad_index = 7 input_player3_joypad_index = 5 input_player4_joypad_index = 6

— Reply to this email directly, view it on GitHub https://github.com/libretro/RetroArch/issues/7638#issuecomment-1694206114, or unsubscribe https://github.com/notifications/unsubscribe-auth/A52OIULSKPBNBVAHHBNBHV3XXGOLJANCNFSM4GGETPGA . You are receiving this because you were mentioned.Message ID: @.***>

''' Created on Jan 28, 2023

@author: drlucid ''' import subprocess import re from re import match import os try: from configparser import ConfigParser except ImportError: from ConfigParser import ConfigParser # ver. < 3.0

if name == 'main':

ini_filepath = 'remapIdentifiers.ini'

config = ConfigParser(allow_no_value = True);
config['mouse_keys'] = {};
config['joy_keys'] = {};
config['remap_files'] = {};
config['files_to_change_keys'] = {};
config['mouse_player1_keys'] = {};
config['mouse_player1_disabled'] = {};
config['mouse_player2_keys'] = {};
config['mouse_player2_disabled'] = {};
config['mouse_player3_keys'] = {};
config['mouse_player3_disabled'] = {};
config['mouse_player4_keys'] = {};
config['mouse_player4_disabled'] = {};
config['joy_player1_keys'] = {};
config['joy_player1_disabled'] = {};
config['joy_player2_keys'] = {};
config['joy_player2_disabled'] = {};
config['joy_player3_keys'] = {};
config['joy_player3_disabled'] = {};
config['joy_player4_keys'] = {};
config['joy_player4_disabled'] = {};
    
config.read(ini_filepath)
    
mouseIniKeys = list(config['mouse_keys'].keys());
mouseIniIdentifiers = [config['mouse_keys'][key] for key in mouseIniKeys];
                    
joyIniKeys = list(config['joy_keys'].keys());
joyIniIdentifiers = [config['joy_keys'][key] for key in joyIniKeys];

remappedMouseIndices =  [False for mouseIniKey in mouseIniKeys]
remappedJoyIndices = [False for joyIniKey in joyIniKeys];

mouseCurrIdentifiers = [];
joyCurrIdentifiers = [];

filesToChange = list(config['remap_files']);
                 
coreFilesToChange = list(config['files_to_change_keys']);

coreFileChangeMouseKeys = [];
coreFileMouseDefaultValues  = [];
coreFileMouseDisabledValues = [];
mouse_player_sections          = ['mouse_player1_keys'    , 'mouse_player2_keys',     'mouse_player3_keys'    , 'mouse_player4_keys'];
mouse_player_disabled_sections = ['mouse_player1_disabled', 'mouse_player2_disabled', 'mouse_player3_disabled', 'mouse_player4_disabled'];
for index in range(len(mouse_player_sections)):
    coreFileChangeMouseKeys.append([]);
    coreFileMouseDefaultValues.append({});
    coreFileMouseDisabledValues.append({});
    for key in list(config[mouse_player_sections[index]].keys()):
        coreFileChangeMouseKeys[-1].append(key);
        coreFileMouseDefaultValues [-1][key] = config[mouse_player_sections[index]][key];
        coreFileMouseDisabledValues[-1][key] = config[mouse_player_disabled_sections[index]][key];
        
coreFileChangeJoyKeys = [];
coreFileJoyDefaultValues  = [];
coreFileJoyDisabledValues = [];
joy_player_sections          = ['joy_player1_keys'    , 'joy_player2_keys'    , 'joy_player3_keys'    , 'joy_player4_keys'];
joy_player_disabled_sections = ['joy_player1_disabled', 'joy_player2_disabled', 'joy_player3_disabled', 'joy_player4_disabled'];
for index in range(len(joy_player_sections)):
    coreFileChangeJoyKeys.append([]);
    coreFileJoyDefaultValues.append({});
    coreFileJoyDisabledValues.append({});
    for key in list(config[joy_player_sections[index]].keys()):
        coreFileChangeJoyKeys[-1].append(key);
        coreFileJoyDefaultValues [-1][key] = config[joy_player_sections[index]][key];
        coreFileJoyDisabledValues[-1][key] = config[joy_player_disabled_sections[index]][key];

p = subprocess.Popen(os.path.join(os.path.dirname(__file__), 'ControllerRemap.exe') + " /list", stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate();
p_status = p.wait();
bMouse = False;
bJoystick = False;
for line in output.splitlines():
    line = str(line, encoding='utf-8', errors='strict');
    if re.search('^Mouse Device List.*', line):
            bJoystick = False;
            bMouse = True;
            continue;
    elif re.search('^Joystick Device List.*', line):
            bJoystick = True;
            bMouse = False;
            continue;
    if bJoystick | bMouse:
        match = re.search("([0-9]+)\..*'(.*)", line);
        if bool(match) & bJoystick:
            joyCurrIdentifiers.append(match[2]);
        elif bool(match) & bMouse:
            mouseCurrIdentifiers.append(match[2]);

for [IniIdentifiers, iniKeys, currIdentifiers, remappedIndices] in zip([mouseIniIdentifiers, joyIniIdentifiers], [mouseIniKeys, joyIniKeys], [mouseCurrIdentifiers, joyCurrIdentifiers], [remappedMouseIndices, remappedJoyIndices]):
    currIndices = [];
    for index in range(len(currIdentifiers)-1, -1, -1):
        currIndices.append(index);
        
    index = 0;
    newIniIndices = [None]*len(iniKeys); #which indices will belong with iniKeys
    for index in range(len(iniKeys)):
        try:
            tempIndex = list.index(currIdentifiers, IniIdentifiers[index]); #see which current identifier matches up with ini identifier
            newIniIndices[index] = currIndices[tempIndex]; #update replacement index with associated index from currIndices
        except:
            newIniIndices[index] = None;
        
    
    for fileToChange in filesToChange:
        with open(fileToChange) as f:
            fileLines = f.readlines();
            f.close();
        with open(fileToChange, 'w') as f:
            for line in fileLines:
                bFoundOne = False;
                for index in range(len(iniKeys)):
                    if re.search('^' + iniKeys[index], line):
                        #need to remap this key
                        if newIniIndices[index] != None:
                            f.write(iniKeys[index] + " = " + str(newIniIndices[index]) + '\n');
                            remappedIndices[index] = True;
                        else:
                            f.write(iniKeys[index] + " = " + str(-1) + '\n');
                        bFoundOne = True;
                        break;
                if not bFoundOne:
                    f.write(line);
            f.close();

for [coreFileChangeKeys, coreFileDefaultValues, coreFileDisabledValues] in zip([coreFileChangeMouseKeys,     coreFileChangeJoyKeys],
                                                                               [coreFileMouseDefaultValues,  coreFileJoyDefaultValues],
                                                                               [coreFileMouseDisabledValues, coreFileJoyDisabledValues]):
    for coreFileToChange in coreFilesToChange:
        with open(coreFileToChange) as f:
            fileLines = f.readlines();
            f.close();
            with open(coreFileToChange, 'w') as f:
                for line in fileLines:
                    bFoundOne = False;
                    for index in range(len(coreFileChangeKeys)):
                        for keyToChange in coreFileChangeKeys[index]:
                            if re.search('^' + keyToChange, line):
                                #need to remap this key to default value if successful in finding the controller, otherwise disable
                                if remappedMouseIndices[index]:
                                    f.write(keyToChange + " = " + coreFileDefaultValues[index][keyToChange] + '\n');
                                else:
                                    f.write(keyToChange + " = " + coreFileDisabledValues[index][keyToChange] + '\n');
                                bFoundOne = True;
                                break;
                    if not bFoundOne:
                        f.write(line);
                f.close();

drlucid avatar Aug 26 '23 12:08 drlucid

Okay, there was an issue with my fix, it broke the mouse identifiers. So, now, the attached should work with both.

For the gamecube, or anything that is not fully encased by single quotes, include everything including the single quotes in the identifier and whatever is after the single quotes, e.g. 'GameCube Controller Adapter', ID=14 For the mouse devices, or anything that is fully encased by single quotes, e.g. HID#VID_046D_PID_C062#7_219e267b_1_0000#

This modified version appears to work as advertised above, let me know if it does and I will create a new version with some additional documentation to explain above.

On Sat, Aug 26, 2023 at 6:03 AM Russell Hofer @.***> wrote:

The problem is my original assumption was that the unique identifier would be encased in single quotes. For the HID devices it is, but for the game controllers just 'GameCube Controller Adapter' is what is encased in single quotes which is obviously not unique. It is a really simple fix.

Give this a try and tell me if it works, and I will update the zip file for future users.

On Sat, Aug 26, 2023 at 1:09 AM Shinlowneogetter @.***> wrote:

@drlucid https://github.com/drlucid Here is the problem, i have 4 gamecube controllers

2023-08-26T09:00:43 ControllerRemap Utility v0.0.11.0 - For Mame (c) 2011 drventure Enterprises

2023-08-26T09:00:43 2023-08-26T09:00:43 Joystick Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'Controller (XBOX 360 For Windows)', ID=3 2023-08-26T09:00:43 2. 'Controller (XBOX 360 For Windows)', ID=2 2023-08-26T09:00:43 3. 'GameCube Controller Adapter', ID=12 2023-08-26T09:00:43 4. 'USB_Game12', ID=11 2023-08-26T09:00:43 5. 'GameCube Controller Adapter', ID=15 2023-08-26T09:00:43 6. 'GameCube Controller Adapter', ID=13 2023-08-26T09:00:43 7. 'GameCube Controller Adapter', ID=14 2023-08-26T09:00:43 8. 'JUYAO Dual Arcade', ID=0 2023-08-26T09:00:43 9. 'JUYAO Dual Arcade', ID=1 2023-08-26T09:00:43 2023-08-26T09:00:43 Mouse Device List (Devices are in enumeration order) ... 2023-08-26T09:00:43 2023-08-26T09:00:43 1. 'HID#VID_0461_PID_4D15#7_3a9bae7e_0_0000#' 2023-08-26T09:00:43 2. 'HID#VID_0079_PID_1802_MI_01_Col01#9_1f1dbd06_0_0000#' 2023-08-26T09:00:43 3. 'HID#VID_0079_PID_1802_MI_01_Col01#8_a4751fc_0_0000#' 2023-08-26T09:00:43 4. 'HID#VID_0000_PID_3825#8_30bac947_1_0000#' 2023-08-26T09:00:43 5. 'HID#VID_0461_PID_4E35#8_292af9fc_0_0000#' 2023-08-26T09:00:43 6. 'HID#VID_0000_PID_3825#8_15447cba_2_0000#' 2023-08-26T09:00:43 7. 'HID#VID_046D_PID_C062#7_219e267b_1_0000#' 2023-08-26T09:00:43 2023-08-26T09:00:43 End of list

When i copy and paste , it don't works: input_player1_joypad_index = GameCube Controller Adapter, ID=12 input_player2_joypad_index = GameCube Controller Adapter, ID=15 input_player3_joypad_index = GameCube Controller Adapter, ID=13 input_player4_joypad_index = GameCube Controller Adapter, ID=14

in dolphin.cfg it return -1

if i copy and paste this: input_player1_joypad_index = GameCube Controller Adapter input_player2_joypad_index = GameCube Controller Adapter input_player3_joypad_index = GameCube Controller Adapter input_player4_joypad_index = GameCube Controller Adapter

in dolphin-emu.cfg input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9 input_player1_joypad_index = 9

the problem is that all are positioned in 9

if i put manually in retroarch settings the 4 controllers temporary directly here the cfg: input_player1_joypad_index = 3 input_player2_joypad_index = 7 input_player3_joypad_index = 5 input_player4_joypad_index = 6

— Reply to this email directly, view it on GitHub https://github.com/libretro/RetroArch/issues/7638#issuecomment-1694206114, or unsubscribe https://github.com/notifications/unsubscribe-auth/A52OIULSKPBNBVAHHBNBHV3XXGOLJANCNFSM4GGETPGA . You are receiving this because you were mentioned.Message ID: @.***>

''' Created on Jan 28, 2023

@author: drlucid ''' import subprocess import re from re import match import os try: from configparser import ConfigParser except ImportError: from ConfigParser import ConfigParser # ver. < 3.0

if name == 'main':

ini_filepath = 'remapIdentifiers.ini'

config = ConfigParser(allow_no_value = True);
config['mouse_keys'] = {};
config['joy_keys'] = {};
config['remap_files'] = {};
config['files_to_change_keys'] = {};
config['mouse_player1_keys'] = {};
config['mouse_player1_disabled'] = {};
config['mouse_player2_keys'] = {};
config['mouse_player2_disabled'] = {};
config['mouse_player3_keys'] = {};
config['mouse_player3_disabled'] = {};
config['mouse_player4_keys'] = {};
config['mouse_player4_disabled'] = {};
config['joy_player1_keys'] = {};
config['joy_player1_disabled'] = {};
config['joy_player2_keys'] = {};
config['joy_player2_disabled'] = {};
config['joy_player3_keys'] = {};
config['joy_player3_disabled'] = {};
config['joy_player4_keys'] = {};
config['joy_player4_disabled'] = {};
    
config.read(ini_filepath)
    
mouseIniKeys = list(config['mouse_keys'].keys());
mouseIniIdentifiers = [config['mouse_keys'][key] for key in mouseIniKeys];
                    
joyIniKeys = list(config['joy_keys'].keys());
joyIniIdentifiers = [config['joy_keys'][key] for key in joyIniKeys];

remappedMouseIndices =  [False for mouseIniKey in mouseIniKeys]
remappedJoyIndices = [False for joyIniKey in joyIniKeys];

mouseCurrIdentifiers = [];
joyCurrIdentifiers = [];

filesToChange = list(config['remap_files']);
                 
coreFilesToChange = list(config['files_to_change_keys']);

coreFileChangeMouseKeys = [];
coreFileMouseDefaultValues  = [];
coreFileMouseDisabledValues = [];
mouse_player_sections          = ['mouse_player1_keys'    , 'mouse_player2_keys',     'mouse_player3_keys'    , 'mouse_player4_keys'];
mouse_player_disabled_sections = ['mouse_player1_disabled', 'mouse_player2_disabled', 'mouse_player3_disabled', 'mouse_player4_disabled'];
for index in range(len(mouse_player_sections)):
    coreFileChangeMouseKeys.append([]);
    coreFileMouseDefaultValues.append({});
    coreFileMouseDisabledValues.append({});
    for key in list(config[mouse_player_sections[index]].keys()):
        coreFileChangeMouseKeys[-1].append(key);
        coreFileMouseDefaultValues [-1][key] = config[mouse_player_sections[index]][key];
        coreFileMouseDisabledValues[-1][key] = config[mouse_player_disabled_sections[index]][key];
        
coreFileChangeJoyKeys = [];
coreFileJoyDefaultValues  = [];
coreFileJoyDisabledValues = [];
joy_player_sections          = ['joy_player1_keys'    , 'joy_player2_keys'    , 'joy_player3_keys'    , 'joy_player4_keys'];
joy_player_disabled_sections = ['joy_player1_disabled', 'joy_player2_disabled', 'joy_player3_disabled', 'joy_player4_disabled'];
for index in range(len(joy_player_sections)):
    coreFileChangeJoyKeys.append([]);
    coreFileJoyDefaultValues.append({});
    coreFileJoyDisabledValues.append({});
    for key in list(config[joy_player_sections[index]].keys()):
        coreFileChangeJoyKeys[-1].append(key);
        coreFileJoyDefaultValues [-1][key] = config[joy_player_sections[index]][key];
        coreFileJoyDisabledValues[-1][key] = config[joy_player_disabled_sections[index]][key];

p = subprocess.Popen(os.path.join(os.path.dirname(__file__), 'ControllerRemap.exe') + " /list", stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate();
p_status = p.wait();
bMouse = False;
bJoystick = False;
for line in output.splitlines():
    line = str(line, encoding='utf-8', errors='strict');
    if re.search('^Mouse Device List.*', line):
            bJoystick = False;
            bMouse = True;
            continue;
    elif re.search('^Joystick Device List.*', line):
            bJoystick = True;
            bMouse = False;
            continue;
    if bJoystick | bMouse:
        match = re.search("([0-9]+)\.[^']*(?:'(?=.*'$))?(.*?)'?$", line);
        if bool(match) & bJoystick:
            joyCurrIdentifiers.append(match[2]);
        elif bool(match) & bMouse:
            mouseCurrIdentifiers.append(match[2]);

for [IniIdentifiers, iniKeys, currIdentifiers, remappedIndices] in zip([mouseIniIdentifiers, joyIniIdentifiers], [mouseIniKeys, joyIniKeys], [mouseCurrIdentifiers, joyCurrIdentifiers], [remappedMouseIndices, remappedJoyIndices]):
    currIndices = [];
    for index in range(len(currIdentifiers)-1, -1, -1):
        currIndices.append(index);
        
    index = 0;
    newIniIndices = [None]*len(iniKeys); #which indices will belong with iniKeys
    for index in range(len(iniKeys)):
        try:
            tempIndex = list.index(currIdentifiers, IniIdentifiers[index]); #see which current identifier matches up with ini identifier
            newIniIndices[index] = currIndices[tempIndex]; #update replacement index with associated index from currIndices
        except:
            newIniIndices[index] = None;
        
    
    for fileToChange in filesToChange:
        with open(fileToChange) as f:
            fileLines = f.readlines();
            f.close();
        with open(fileToChange, 'w') as f:
            for line in fileLines:
                bFoundOne = False;
                for index in range(len(iniKeys)):
                    if re.search('^' + iniKeys[index], line):
                        #need to remap this key
                        if newIniIndices[index] != None:
                            f.write(iniKeys[index] + " = " + str(newIniIndices[index]) + '\n');
                            remappedIndices[index] = True;
                        else:
                            f.write(iniKeys[index] + " = " + str(-1) + '\n');
                        bFoundOne = True;
                        break;
                if not bFoundOne:
                    f.write(line);
            f.close();

for [coreFileChangeKeys, coreFileDefaultValues, coreFileDisabledValues] in zip([coreFileChangeMouseKeys,     coreFileChangeJoyKeys],
                                                                               [coreFileMouseDefaultValues,  coreFileJoyDefaultValues],
                                                                               [coreFileMouseDisabledValues, coreFileJoyDisabledValues]):
    for coreFileToChange in coreFilesToChange:
        with open(coreFileToChange) as f:
            fileLines = f.readlines();
            f.close();
            with open(coreFileToChange, 'w') as f:
                for line in fileLines:
                    bFoundOne = False;
                    for index in range(len(coreFileChangeKeys)):
                        for keyToChange in coreFileChangeKeys[index]:
                            if re.search('^' + keyToChange, line):
                                #need to remap this key to default value if successful in finding the controller, otherwise disable
                                if remappedMouseIndices[index]:
                                    f.write(keyToChange + " = " + coreFileDefaultValues[index][keyToChange] + '\n');
                                else:
                                    f.write(keyToChange + " = " + coreFileDisabledValues[index][keyToChange] + '\n');
                                bFoundOne = True;
                                break;
                    if not bFoundOne:
                        f.write(line);
                f.close();

drlucid avatar Aug 26 '23 13:08 drlucid