Howdy, Stranger!

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

Supported by

[solved] collecting mouse and keyboard response while showing stimuli

edited January 2014 in OpenSesame

Hi,

my name is Stefano and I am quite new to OpenSesame, although I really like it already. But I need some help implementing a dual task

Basically I want to show a stimulus with 4 rectangles and a line of text for 1500ms. The colors of the rectangles, and the text to be displayed are defined in a loop, and while the stimulus is on the screen I want to monitor for 1500 ms (the duration of the stimulus on the screen) both mouse clicks and keybord responses. In fact there are two simultaneous task to be performed: a) checking whethere 3 or more rectangles have the same fill color, and press space if that is the case, and b) whether there is a colon in the text line, and click on the mouse if that is the case. After a click or a keystroke, anyway, the stimulus must stay on the screen until 1500 ms have elapsed from the stimulus onset.

Given that there are two tasks to be performed simultaneously, in each trial there are two correct responses, one for task (a) and one for task (b), and I have set variables in the loop of condition to store (a) whether there are 3 or more rectangles of the same color or not (variable "correct_response", values: "space" if there are 3 or more rectangles with same fill color; "a" otherwise), (b) whether there is a colon in the text (variable "colon", values: 1 if there is a colon, 0 otherwise). For each task, at the end of a trial, I want to record in a variable whether there was a hit (the target condition was present, and the subject gave the correct response), a miss (the target was present, but the subject did not respond within 1500 ms) or an incorrect response (the target was NOT present, and the subject did respond as it was present).

I guess I need inline script to do that, but I'm not sure how to use them. Can anyone please help?

Thanks you in advance for any help you can provide me!

best,
Stefano

Comments

  • edited 7:58PM

    I forgot to say that in each trial, if there are not 3 or more rectangles of the same color, the subject should not press any key, and if there is not a colon in the text line, the subject should not click on the mouse button. In other words, each of the possible responses (keystroke and mouseclick) should be given if and only if the corresponding target is present.

  • edited 7:58PM

    Hi Stefano,

    Right, you can certainly do this. It would require a bit of inline-code, but nothing overwhelming. But I was thinking (just a suggestion, perhaps you have good reasons for the paradigm as is) that the paradigm could be simplified a bit. What if you just define 4 keys, say like so:

    • z : rectangles present, colon present
    • x : rectangles present, colon absent
    • n : rectangles absent, colon absent
    • m : rectangles absent, colon present

    If you decide to do it like this, you would always have one single response to each display, and you could use a single keyboard-response. The only thing that remains then, would be to pad the 1500ms using inline code (so that the display doesn't disappear when the participant presses a key) with an inline_script like this:

    self.sleep(1500-self.get('response_time'))

    Does this make sense?

    So that would be an option. If you don't think this is a good idea, could you please describe in more detail how you would like to handle responses? More specifically, is the participant allowed to press both the mouse and the key at any time, or is there a fixed order: first the key, than the mouse, or vice versa?

    Cheers,
    Sebastiaan

  • edited January 2014

    Hi Sebastiaan,

    thanks for your prompt reply! I had thought initially about a solution like the one you suggested, but I discarded it for design reasons. In fact, I want the two tasks to be more separate, and independent among each other, and doing like you say would be like having a single task, with 4 possible responses to memorize, thus more complicated than two simple "press/click-if-target-is present" tasks. I have tried to code the inline script below, and I get a syntax error at the line in which I call self.time() and can't go forward. In any way I'm also starting to figure out why (syntax error aside) this algorithm can't work: I guess that is because once you call a keyboard() function, the program start waiting, and so you can't immediately after call a mouse() function!. So we could at least simplify to have the user only use keyboard to express responses, allowing him to do it twice in each trial (in case the target is present in both tasks), regardless of the order of responses.

        ___run__
        from openexp.keyboard import keyboard
        from openexp.mouse import mouse
    
        timeout = 1500
        start_time = self.time()
    
        my_keyboard = keyboard(self.experiment, timeout= timeout)
        #my_mouse = mouse(self.experiment,  timeout= timeout) 
    
        my_keyboard.flush()
    
        # show stimuli
        self.c.show() 
        key = None
    
        if ! my_mouse.flush():
            click = None
    
        elapsed_time = 0
        while  elapsed_time <1500:
            while key == None | click= None:
    
            if key == None:
                key, key_end_time = my_keyboard.get_key()
            if click == None:
                click, position, click_end_time = my_mouse.get_click()
    
            elapsed_time = self.time() - start_time
    
        # response checking for both tasks
    
        if self.experiment.get("correct_response") == "a":
            if key == None:
                self.experiment.set("task1_correct", 1)
    
            else:
                self.experiment.set("task1_correct", 0)
    
        else:
            if key == "space":
                self.experiment.set("task1_correct", 1)
    
            else:
                self.experiment.set("task1_correct", 0)
    
        if self.experiment.get("virgola") == 0:
            if mouse == None:
                self.experiment.set("task2_correct", 1)
    
            else:
                self.experiment.set("task2_correct", 0)
    
        else:
            if mouse == "space":
                self.experiment.set("task2_correct", 1)
    
            else:
                self.experiment.set("task2_correct", 0)
    
        self.experiment.set("response_risposta_tastiera", my_keyboard.to_chr(key))
        self.experiment.set("response_risposta_mouse", mouse)
    
        # interstimolo
        self.sleep(250)
    
        __end__
        ___prepare__
        from openexp.canvas import canvas
    
        # richiama dal loop i colori dei quadrati ed il testo
        colore1=self.experiment.get("color1")
        colore2=self.experiment.get("color2")
        colore3=self.experiment.get("color3")
        colore4=self.experiment.get("color4")
        testo=self.experiment.get("testo")
    
        #prepara gli stimoli
        self.c = self.offline_canvas()
        self.c.set_font(mono,  24)
        self.c.rect(288, -200, 192, 192, fill=True, color=colore1)
        self.c.rect(-224, -200 , 192, 192, fill=True, color=colore2)
        self.c.rect(-480, -200, 192, 192, fill=True, color=colore3)
        self.c.rect(32, -200, 192, 192, fill=True, color=colore4 )
        self.c.text( testo, center=True, color=white)
        __end__
        set description "Executes Python code"
    
    

    Please let me know what you think and thank you a lot for your precious help (and for OpenSesame in general too!)

    Stefano

  • edited 7:58PM

    Hi Stefano,

    From what I can tell from the code, you're almost there. The only real problem appears to be the timeout. You now pass '1500' as a timeout to the keyboard and mouse classes. This means that get_key() and get_click() will block for 1500ms before returning a timeout.

    What you actually want to do is set the timeout really low, to say 5ms. This way the keyboard and mouse can be polled intermittently, if you understand what I mean. Because you have a while loop that blocks for 1500ms (while elapsed_time <1500:) you will still have a 1500ms timeout, even though the timeout for each individual call of get_key() and get_click() is much lower.

    Regarding the error: I don't see a syntax error in the line that says:

    elapsed_time = self.time() - start_time

    Is it maybe an indentation issue or something?

    Good luck,
    Sebastiaan

  • edited January 2014

    Hi Sebastiaan,

    thanks to your advice now I'm almost there! The only part of the script that doesn't seem to work is at the end of the run phase, when I want to clear the canvass and wait for 250ms before moving to the next trial. Any ideas about why the code I wrote is not working?

        ___run__
        from openexp.keyboard import keyboard
        from openexp.mouse import mouse
    
        timeout = 5
    
        my_keyboard = keyboard(self.experiment, timeout= timeout)
        start_time = self.time()
        my_mouse = mouse(self.experiment,  timeout= timeout) 
        my_keyboard.flush()
    
        # show stimuli
        self.c.show() 
    
        key = None
        if my_mouse.flush() == False:  click = None
    
        elapsed_time = 0
    
        while  elapsed_time <1500:
            if key == None:
                key, key_end_time = my_keyboard.get_key()
            if click == None:
                click, position, click_end_time = my_mouse.get_click()
            elapsed_time = self.time() - start_time
    
        # response checking for both tasks
        if self.experiment.get("correct_response") == "a":
            if key == None:
                self.experiment.set("task1_correct", 1)
            else:
                self.experiment.set("task1_correct", 0)
        else:
            if key == "space":
                self.experiment.set("task1_correct", 1)
            else:
                self.experiment.set("task1_correct", 0)
        if self.experiment.get("virgola") == 0:
            if click == None:
                self.experiment.set("task2_correct", 1)
            else:
                self.experiment.set("task2_correct", 0)
        else:
            if click == 1:
                self.experiment.set("task2_correct", 1)
            else:
                self.experiment.set("task2_correct", 0)
    
        #
        self.c.clear()#
        self.experiment.sleep(250)
        self.experiment.set("response_risposta_tastiera", my_keyboard.to_chr(key))
        self.experiment.set("response_risposta_mouse", click)
        __end__
        ___prepare__
        from openexp.canvas import canvas
    
        # richiama dal loop i colori dei quadrati ed il testo
        colore1=self.experiment.get("color1")
        colore2=self.experiment.get("color2")
        colore3=self.experiment.get("color3")
        colore4=self.experiment.get("color4")
        testo=self.experiment.get("testo")#
    
        self.c = self.offline_canvas()#
    
        self.c.set_font("Mono",24)#
    
        self.c.rect(288, -200, 192, 192, True, colore1)
        self.c.rect(85, 20, 192, 192, True, colore1)
        self.c.rect(307, 20 , 192, 192, fill=True, color=colore2)
        self.c.rect(527, 20, 192, 192, fill=True, color=colore3)
        self.c.rect(749, 20, 192, 192, fill=True, color=colore4 )
        self.c.text( testo, center=True, color="white")
        __end__
        set description "Executes Python code"
    

    Thank you again a lot for your help!

    Have a nice weekend
    Stefano

  • edited 7:58PM

    Hi Stefano,

    Yep. self.c.clear() only clears the offline canvas (self.c), but does not update the display. So you would have to do a self.c.show() as well in order to show the cleared canvas (effectively blanking the screen).

    Of course, you could also just insert a 250ms blank sketchpad after the inline_script. That would save you the (small) trouble of scripting.

    Cheers,
    Sebastiaan

  • edited 7:58PM

    Ok now I get it, thanks. In the meantime, however, I had already done what you were suggesting, inserting a blank sketchpad after the inline script :-) But thank you so much anyway!

    Best,
    Stefano

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