Recording Responses from 4-Button Device in PsychoPy

Hello everyone,

I am currently setting up an experiment in PsychoPy where participants in an fMRI scanner use a 4-button response device to answer questions. Each button on the device corresponds to an answer option (1, 2, 3, or 4). The responses from this 4-button device are correctly saved in a text file on the computer, and we can see the values (1, 2, 3, 4) in the file.

However, I am facing an issue where PsychoPy does not recognize the input from the 4-button device during the experiment. I have tried using different components such as the keyboard response, joystick response, and button response in the PsychoPy Builder, but none of these seem to detect the responses from the 4-button device. I would like psychoPy detect the button response, move to next question and save the response.

Has anyone encountered a similar issue or have any suggestions on how to get PsychoPy to recognize and record the responses from this specific 4-button device? Any insights or solutions would be greatly appreciated.

Thank you!

Which 4-button device model are you using?

We are using CurrentDesign 4 button device.

I tried to use two different response types to get input from the 4-button device: Buttonbox and keyboard response and none of them worked.

I do not have expertise in coding, but with the help of the ChatGPT I tried to modify the code as indicated below:

I tried to define the button map at the beginning of the code:

from psychopy import core, event

Dictionary to store button mappings (adjust as needed)

button_map = {
‘1’: ‘button1’,
‘2’: ‘button2’,
‘3’: ‘button3’,
‘4’: ‘button4’
}

Initialize response storage

responses =

Then for each frame, I added this code:

keys = event.getKeys() # For keyboard-like input

for key in keys:
if key in button_map:
responses.append(button_map[key])
thisExp.addData(‘response’, button_map[key])
thisExp.addData(‘rt’, t)
continueRoutine = False # End routine on response (adjust as needed)

if responses:
thisExp.addData(‘responses’, responses)
else:
thisExp.addData(‘responses’, ‘None’)

However, this did not work either.

I also tried to define the input methods at the beginning of the code:

import serial

ser = serial.Serial(‘COM3’, 1200)

and in each frame tab, I added this code:

if ser.in_waiting:
key = ser.read().decode(‘utf-8’).strip()
if key in button_map:
responses.append(button_map[key])
thisExp.addData(‘response’, button_map[key])
thisExp.addData(‘rt’, t)
continueRoutine = False # End routine on response

It also did not work.

I am not sure what to do to get input from the 4-button device.

Thank you for your consideration,
Kind regards