psychopy.org | Reference | Downloads | Github

Use key responses as triggers

I need to send the trigger according to the response the person gives. The responses are collected using keyboard component of the builder. The 8 allowed keys are from ‘f1’ to ‘f8’. The triggers that I send are very strange and every time different even if participant presses the same response button.

I use different version of the code with the simplest idea, but it does not work:

#this sends the first trigger that is taken from the excel file, and it works fine
parallel.setData(stimul_type)
core.wait(0.1)
parallel.setData(0)

#the second trigger should be sent 8 seconds later, and it should consist of the concatenation of the stimulus #type and the response given by the participant

core.wait(8)
x=key_resp_run1.keys #this should catch what response the participant chose, from f1 to f8
y=stimul_type #this is taken from the excel file
z=str(y)+str(x) #this concatenates the stimulus type and the response, for example,
#if the stimulus type is “4” and the response of the participant is “f5”, I want the trigger 4f5
parallel.setData(z)
core.wait(0.5)
parallel.setData(0)

the triggers which are sent are sometimes 2-digit, sometimes 3-digit, and even if the same stimulus type and response are pressed, the triggers that are sent are different.
I guess, the problem is in the line
x=key_resp_run1.keys #key_resp_run1 is the name of the keyboard component

Your problem is here:

As the API shows (http://www.psychopy.org/api/parallel.html), the .setData() function sends one byte. You are feeding it a multi-character string, which by definition will contain more than one byte’s worth of data.

The parallel port is a very low level interface in this day and age. You are literally controlling the voltages on individual lines in a cable. You can’t just send arbitrary information on that old-school channel.