PsychoPy not detecting joystick in 2025.x.x

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Windows 11 Enterprise 26100.7623
PsychoPy version (e.g. 2024.2.4 Py 3.8): 2025.2.4beta, Python 3.10.11, pygame 2.6.1 (SDL 2.28.4)
Standard Standalone Installation? (y/n) Yes
Do you want it to also run online? (y/n) No
What are you trying to achieve?: Use my joystick in 2025.1.1 Py 3.8, or 2025.x.x Py3.10

Hi all, I’m running into a joystick‑detection issue that I can’t resolve, and I’d appreciate guidance on whether this is a configuration problem on my end or a regression in recent PsychoPy releases. My same joystick worked in the past on the same PC with older 2024.x.x PsychoPy installs. Windows and other applications detect the joystick and all buttons as expected.

What did you try to make it work?

  1. Tried to produce a minimal task example in 2025.1.1 Py 3.8, and 2025.2.4 Py3.10, that contains only a single joystick component. Here the error is ERROR No joystick/gamepad device found
  2. I tested whether I could detect the joystick in a single code component in PsychoPy 2025.2.4 using count = joysticklib.getNumJoysticks(), but I get:
    AttributeError: module psychopy.hardware.joystick’ has no attribute ‘getNumJoysticks’. Did you mean: getAllJoysticks’?. Changing the code component to count = joysticklib.getAllJoysticks() results in [{‘index’: 0, ‘name’: ‘Logitech Attack 3’}]. However, if I add in a joystick component the No joystick/gamepad device found error occurs.
  3. I looked in the python script generated by the minimal task example, and the error appears to relate to a flag included by the joystick component where joysticklib.getNumJoysticks() is not detecting the joystick (below):
    # Start Code - component code to be run after the window creation
    from psychopy.hardware import joystick as joysticklib  # joystick/gamepad accsss
    from psychopy.experiment.components.joystick import virtualJoystick as virtualjoysticklib
    from psychopy.hardware import joystick as joysticklib  # joystick/gamepad accsss
    from psychopy.experiment.components.joyButtons import virtualJoyButtons as virtualjoybuttonslib
    
    # --- Initialize components for Routine "joy" ---
    x, y = [None, None]
    joystick = type('', (), {})() # Create an object to use as a name space
    joystick.device = None
    joystick.device_number = 0
    joystick.joystickClock = core.Clock()
    joystick.xFactor = 1
    joystick.yFactor = 1
    
    try:
        numJoysticks = joysticklib.getNumJoysticks()
        if numJoysticks > 0:
            try:
                joystickCache
            except NameError:
                joystickCache={}
            if not 0 in joystickCache:
                joystickCache[0] = joysticklib.Joystick(0)
            joystick.device = joystickCache[0]
            if win.units == 'height':
                joystick.xFactor = 0.5 * win.size[0]/win.size[1]
                joystick.yFactor = 0.5
        else:
            joystick.device = virtualjoysticklib.VirtualJoystick(0)
            logging.warning("joystick_{}: Using keyboard+mouse emulation 'ctrl' + 'Alt' + digit.".format(joystick.device_number))
    except Exception:
        pass
        
    if not joystick.device:
        logging.error('No joystick/gamepad device found.')
        core.quit()
  1. I tried to locate or add the joystick device in PsychoPy 2025.2.5 new Device Manager option - but the joystick is not listed.
  2. I tested whether pygame could detect the joystick using PsychoPy’s python install accessed via the command line. pygame.joystick.init() detected the joystick :+1:

Link to the most relevant existing thread you have found:

I could not find any joystick posts related to detection errors on this forum. But I notice this recent changelog for 2025.2.4 Py3.10 describing “Fixed incorrect func ref in getAllJoysticks()". Click here

I have determined a solution. My joystick is now detected and working as expected.

It seems that a recent change to PsychoPy broke the joystick component initialisation script. I fixed the issue for my tasks by using the script editor to replace all instances of the task code in this snippet:

try:
        numJoysticks = joysticklib.getNumJoysticks()
        if numJoysticks > 0:

with the code in this snippet:

try:
        numJoysticks = joysticklib.getAllJoysticks()
        if len(numJoysticks) > 0:

I then run the task directly using the python script file, not the builder. Running in the Builder overwrites the task script with the broken code.

So, it seems that instead of .get.numJoysticks() in the current joystick routine initialisation code .getAllJoysticks()should be used. Whereas .getNumJoysticks returned a number value, .getAllJoysticks returns a list of dicts. Thus, the the check must also be changed to be if len(numJoysticks) > 0:.

I’ll be testing this with some more example code and more older tasks over the next days and will update here if the fix no longer works.

I hope that this may be useful to others, and that this fix can be implemented into PsychoPy soon.

Thank you.