AndersMalmgren / FreePIE

Programmable Input Emulator
644 stars 144 forks source link

Add a way to identify joystick device by name #221

Closed weezzah closed 1 year ago

weezzah commented 1 year ago

If there is a solution to this, please let me know, but here goes:

This is more of a feature request, but it stems from an issue with how Windows handles game controllers, which gives me an issue in FreePIE. The game controllers list in Windows is often reordered if a device is connected or disconnected. On top of that, vJoy is also put into that list which adds to the shuffling. And other virtual devices do the same, like the 360 controller emulator. This has me writing scripts similar to this:

#  simple example
if starting:
    # set indices as they appear in the windows game controllers list (run cmd: joy.cpl)
    GAMEPAD = 2
    WHEEL = 5

    # vjoy uses its own indexing
    VJOY = 0

if joystick[GAMEPAD].x > 900:
    keyboard.setPressed(Key.A)

vJoy[VJOY].x = joystick[WHEEL].x * -1.0

Whenever I change what is plugged into the pc, I have to go into game controllers and verify that my script indices are set to the correct game controllers. This could be solved by providing some way of identifying joysticks by name instead of with indices, or maybe do something like this:

#  pseudo code
if starting:
    # suggestion: resolve indices with a FreePIE function e.g. getJoystickIndexByName
    GAMEPAD = joystick.getJoystickIndexByName("Logitech Dual Action")

if joystick[GAMEPAD].x > 900:
    keyboard.setPressed(Key.A)

Thoughts?

Edit: There's the possibility of having multiple controllers of same type which means names would be identical. There are unique id's for game controllers that could be used somehow too.

AndersMalmgren commented 1 year ago

You can also send in a string with the name instead of its index. Hope that helps

weezzah commented 1 year ago

Worked like a charm, thank you!

diagnostics.watch(joystick["Logitech Dual Action"].x)
AndersMalmgren commented 1 year ago

You can also do

diagnostics.watch(joystick["Controller (Wireless Gamepad F710)", 1].x)

If you want the second controller with a specific name. Hope it helps!

weezzah commented 1 year ago

Excellent solution, safe to say this issue has been solved, thank you again!