Add some functionalities of hardware.keyboard to hardware.joystick

Hello all,
I was wondering how feasible it would be to add functionality to psychopy’s joystick such that it has parameters similar to keyboard.py, for example response time, status, clocks to measure response time, etc. If this is something that could be useful for psychopy, I would be willing to at least start some of this implementation as it would be useful for my current project. If you guys know of better ways to implement these things that does not require changing psychopy itself, I’m all ears.

As a side note, what exactly is the issue with joystick that psychopy needs someone to fix?

Hi there

Fundamentally the operating system treats these rather differently. For keyboards and mice the operating system will return events to indicate a button-down or button-up etc. For joysticks there aren’t events as such, so you have to monitor the current state of the joystick button and detect a down/up event as a change in that current state from the last time you checked (and then check regularly). This is the stuff that’s done automatically on your behalf for the other devices.

Now, there is the JoyButtons Component in the Builder that is designed to do this for you. It essentially extends the Joystick class from the psychopy.hardware package with a class called VirtualJoyButtons and that implements the checks I mention above to compared the current state with the previous state.

That’s all going to operate within the standard frame loop of the Builder experiment. If you want to poll the joystick at a higher rate than your screen refresh then we’d need to look at doing this with ioHub which will probably need input from @sol

so you have to monitor the current state of the joystick button and detect a down/up event as a change in that current state from the last time you checked (and then check regularly)

This is how I’m doing it currently. Good to know that’s how it “should” be done.

I was not aware that there are differences at the OS level. I just assumed it would be treated similarly to a keyboard/mouse. I’ll look more into JoyButtons to see if I can apply it to my project. Thanks for the info!