[open] Saccadic and keyboard responses
Hi,
I'm a new user of OpenSesame and I'm trying to implement my next experiment with it. I'm recording eye movements (with an EyeLink 1000) and at the same time a sequence of key release/key press on a standard keyboard so that at the end of each trial I can calculate the saccadic reaction time and the manual reaction time.
I have tried to script this within a while loop, but the "exp.eyelink.wait_for_saccade_start()" doesn't seem to do the job because it stops the code (if I well understand) until the saccade is detected so that if the keyboard release/press is made before the saccade won't be detected.
The paradigm I'm using is very simple, I have just a fixation followed by the appearance of a lateralised target. After target appearance, I need to record the parameters of the first saccade made to the target, a key release and a subsequent key press.
What would it be the best approach for this type of recording? I would be happy to access to the parameters within the ENDSACC of the first saccade made, so to get saccadic start time, x/y positions etc. and within that loop also control for keyboard events. Something similar to the Matlab code I attached below (plus the keyboard events).
Any idea?
best,
Antimo
count = 0;
while GetSecs()<(TARGET_ONSET+0.5) %check for 500 ms
if count==0
evtype = Eyelink('GetNextDataType');
if evtype==el.ENDSACC && count==0
data = Eyelink('getfloatdata', evtype);
saccadestart = data.sttime;
gaze_stx_temp = data.gstx;
gaze_sty_temp = data.gsty;
gaze_enx_temp = data.genx;
gaze_eny_temp = data.geny;
count = 1;
end
end
end
Comments
Hi Antimo,
If you have used the EyeLink in MatLab before, then you could consider using
pylink
directly, instead of using thelibeyelink
wrapper. This way the API will be more-or-less the same as you're used to, except of course for the syntactic differences between Python and MatLab.An example (untested, from the top of my head):
This will not conflict with the OpenSesame EyeLink plug-ins, by the way, these just provide an alternative (and simpler) API. You can find the PyLink manual on the SR Support forum.
Alternatively, you could use
libeyelink
, and detect saccade onset based on sample position, for example by determining when horizontal gaze crosses some imaginary line. That's what I usually do, actually. In a nutshell:Does that answer your question?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
thanks, this is really helpful and it matches what I was looking for in terms of accessing saccade parameters. My first attempt was actually using the pylink as well, but I must have had some bug in my code because I was not able to get the data I wanted.
Do you have a similar command to access the keyboard functionalities? I can see how to get a key press within a similar loop as above, but I can'd find a command for the key release.
Digging in the forum I found an example for key release using pygame (code below). Would that be appropriate or are there other libraries?
Thanks again, this is really helpful!
Best,
Antimo
No, that's right. The
openexp.keyboard
module does not offer this functionality.It depends on the back-end that you're using in OpenSesame. Both legacy and xpyriment use PyGame under the hood, so when you use these back-ends your code snippet will work. If you use the psycho back-end, things are a bit more tricky. PsychoPy itself does not offer key-release functionality, but you can dig into the underlying library (pyglet) and implement it yourself. The script below illustrates the basic idea.
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
your suggestions have been really clear, but I still have some doubts.
The problem is that I need to check for key release, key press and saccades within the same loop, in order to detect all the events. The functions within the openexp.keyboard module seems to be a "wait function" and this would not work for me because I need to check at every iteration of the loop also for saccades. For this reason I tried to adapt the code you suggested using pygame (and the xpyriment back-end, assuming that will work also with the eyelink plug-in).
The code below gives back reasonable timings and it seems it doesn't stop the code waiting for key press/release events. But since I'm really not familiar with this pygame event handling, I wanted to ask you if you reckon is OK.
It also would be good to have an event.key, as the example posted above, but I cant pull out from the event list this value.
Your help is really appreciated!
Best,
Antimo
Well, you can use
get_key()
to the keyboard by setting the timeout to 0, in which case it won't block the execution of the experiment. But it still won't do you much good, because you need to detect key releases, which theopenexp
module won't do.pygame.event.get()
returns a list,and
you are checking thislist
as if it were abool
(i.e.True
orFalse
). This works, because an empty list will, in this context, evaluate toFalse
, but I think the implementation below is a bit easier to understand. Also, you didn't specify an initial value forduration
, which would trigger a crash if no response was collected. But basically, yes, your logic is fine!Check out SigmundAI.eu for our OpenSesame AI assistant!