Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Saccadic and keyboard responses

edited January 2014 in OpenSesame

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

  • edited January 2014

    Hi Antimo,

    If you have used the EyeLink in MatLab before, then you could consider using pylink directly, instead of using the libeyelink 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):

    import pylink
    evtype = pylink.getEYELINK().getNextData()
    if evtype == pylink.STARTSACC:
        event = pylink.getEYELINK().getFloatData()
        x, y = event.getStartGaze()
        # etc.
    

    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:

    while True:
        x, y = exp.eyelink.sample()
        if x < some_value:
           break # Saccade detected, break from loop
    

    Does that answer your question?

    Cheers,
    Sebastiaan

  • edited 12:43PM

    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

    import pygame
    
    key = None
    T1 = self.time()
    T2 = 5000
    total = T1+T2
    
    while self.time() < total:
    for event in pygame.event.get():
    if event.type == pygame.KEYUP:
    key = event.key
    keytime = self.time
    
    rt = keytime - start_time 
    print '%s was released after %d ms' % (key, rt)
    
  • edited 12:43PM

    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.

    No, that's right. The openexp.keyboard module does not offer this functionality.

    Digging in the forum I found an example for key release using pygame (code below). Would that be appropriate or are there other libraries?

    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.

    import pyglet
    
    def on_key_release(symbol, modifiers):
    
        """
        This function is called by pyglet when a key is released.
    
        Arguments:
        symbol      --  The key that is pressed.
        modifiers   --  A list of keyboard modifiers that may be pressed.
        """
    
        global wait
        wait = False
    
    # Retrieve all PyGlet windows
    wins = pyglet.window.get_platform().get_default_display().get_windows()
    # Set wait to True
    wait = True
    # Use our own `on_key_release` handler
    win.winHandle.on_key_release = on_key_release
    # Wait until a key has been released, in which case wait is set to True. In the
    # meanwhile, keep calling `dispatch_events()` so that PyGlet keeps processing
    # input events.
    while wait:
        for win in wins:
            win.dispatch_events()
    

    Cheers!

  • edited January 2014

    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

    import pygame
    
    count = 0
    key_up = 0
    dummy = 2000
    
    T_onset = self.time()
    while self.time() < T_onset + dummy:
    
        if pygame.event.get(pygame.KEYUP) and count == 0:
            RT_release = self.time()
            #key = event.key
            key_up = 1
            count = 1
        if pygame.event.get(pygame.KEYDOWN) and count == 1:
            RT_pressed = self.time()
            duration = RT_pressed-RT_release
            #key = event.key
            count = 0
    
    rt = RT_release - T_onset
    
    print 'KEY was released after %d ms' % (rt)
    print 'KEY was pressed after %d ms' % (duration)
    
  • edited 12:43PM

    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.

    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 the openexp module won't do.

    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.

    pygame.event.get() returns a list, and you are checking thislist as if it were a bool (i.e. True or False). This works, because an empty list will, in this context, evaluate to False, but I think the implementation below is a bit easier to understand. Also, you didn't specify an initial value for duration, which would trigger a crash if no response was collected. But basically, yes, your logic is fine!

    import pygame
    
    count = 0
    key_up = 0
    dummy = 2000
    duration = -1
    
    T_onset = self.time()
    while self.time() < T_onset + dummy:
        for event in pygame.event.get():
            if event.type == pygame.KEYUP and count == 0:
                count = 1
                RT_release = self.time()
                key_up = 1
                count = 1
            elif event.type == pygame.KEYDOWN and count == 1:
                RT_pressed = self.time()
                duration = RT_pressed-RT_release
                count = 0
    
    rt = RT_release - T_onset
    
    print 'KEY was released after %d ms' % (rt)
    print 'KEY was pressed after %d ms' % (duration)
    
Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games