Howdy, Stranger!

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

Supported by

Logging Multiple Key Duration While Video Running

Hello there,

I currently learning about OpenSesame and find a problem with logging. Here is my experiment that I want to make :
1. There is one video stimulus and it will last long 8 seconds.
2. I want to asses the hallucinations-experiences from participants while they watch the video stimulus.
3. Participant will press and hold "space" when the hallucination comes.
4. I already read your articles in and
5. I think the second link suits me well, but unfortunately the log file is empty
6. What I really need is the key press duration time without forcing video end

Could anyone help me solve this problem?

Kind Regards,


  • Hi Satrio,

    I haven't tried it, but if you modify the code in the link above in this way, does it work?

    # needs to be put in the run phase!!!!
    import pygame
    t0 = clock.time()
    keydown = False
    keyup = False
    timeout = 10000 # how long do you want to wait?, Probably length of video
    while True:  
        # Determine the RT, i.e. the time relative to the loop start
        response_time = clock.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 keyup == True and event.type == pygame.KEYDOWN:
                   keydown =True
            if keydown:
                 if event.type == pygame.KEYUP:
                     var.key =
                     var.respTime = clock.time()
                     keydown = False
                     keyup = True
        if clock.time()-t0 > timeout: 

    Hope this helps.


    Thanked by 1DahmSF
  • Hello Eduard,

    Thanks a lot for your reply! It worked and the log files shown up but unfortunately it was very messy. Also the things that I need (multiple duration key-presses) weren't there.

    For now, I change it into multiple single press with two buttons (z for when they saw the hallucination and m for when they think the hallucination ended) since I still confuse about pygame's syntax. It helps me to fulfill my need now, but I still want to know how to record multiple duration key-presses and I still try to find it hehe. I hope you would continue to discuss this topic until we find it :smiley: .

    Once again, many thanks for you Eduard!

    Kind Regards,

Sign In or Register to comment.