Howdy, Stranger!

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

Supported by

[solved] Log time and duration of multiple key presses

edited October 2014 in OpenSesame

Hello,
I am trying to set up a listening experiment in which I ask the participant, while listening to an audio stimulus, to press a key when they feel a certain emotion and to keep it pressed for as long as they feel this emotion.
I would like to log both the time at which the participants starts pressing the key as well as the duration of the keypress. I tried the inline script found in this post: http://forum.cogsci.nl/index.php?p=/discussion/37/solved-how-to-log-the-duration-of-a-key-press/p1, by adding these two lines to get the exact times:
self.experiment.set("key_up_time", key_up_time)
self.experiment.set("key_down_time", key_down_time)
However, this raises two problems: first of all, the "key_down_time" value is very high, possible counting from the beginning of the experiment and not from the onset of the audio stimulus (of which I set the duration at 0 so it would begin to collect keyboard responses right away). Secondly, this allows me to record only one keypress. Once the key is released, the sequence proceeds to the next item, although the sound is still playing in the background.

What I would like to achieve is for the whole stimulus to be played, during which both the onset time and the duration of each key press is logged. E.g. one could feel an emotion beginning after 10 seconds, feel this emotion for 5 seconds. Than 20 seconds of nothing, and then once again the emotion could reappear for another 40 seconds. For each time the participant presses a key, I would like to log the time at which this happens and the duration of the keypress. Is there any way to do this?

Thank you in advance for your help!

Comments

  • edited October 2014

    Hi Eveline,

    So if I understand correctly, you want to log all key presses and key releases that occur while a sound is playing. Is that right?

    To do this, it's best to use either the legacy or xpyriment back-end. Both of these are built on PyGame, so you can use the PyGame event system. The example script below shows the basic logic.

    I would also consider what you want your logfiles to look like. Your data is essentially continuous, which is difficult to combine with the spreadsheet-like logfile that OpenSesame normally uses. The script below writes lines to the logfile, which you can parse afterwards. But don't combine this with a logger, or your logfiles will become very messy!

    See also:


    import pygame
    t0 = self.time()
    # Loop while a sound is playing
    while pygame.mixer.get_busy():  
        # Determine the RT, i.e. the time relative to the loop start
        response_time = self.time() - t0
        # Get all input events
        for event in pygame.event.get():
            # Print KEYDOWN and KEYUP events, including the key name
            # and the RT.
            if event.type == pygame.KEYDOWN:
                exp.log('KEYDOWN key=%s rt=%d' \
                    % (pygame.key.name(event.key), response_time))
            if event.type == pygame.KEYUP:
                exp.log('KEYUP key=%s rt=%d' \
                    % (pygame.key.name(event.key), response_time))
    

    Cheers,
    Sebastiaan

  • edited 2:27PM

    Hi Sebastiaan,
    Thanks a lot! It works perfectly! This was exactly what I was looking for. I have never programmed in Python before, so I was lost trying to write code myself.
    The logfile isn't too messy, as I don't expect people to press the key very often while listening (probably not more than 1-2 times per stimulus).
    Thanks again for your help.

    Cheers,
    Eveline

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