Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

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 http://forum.cogsci.nl/index.php?p=/discussion/37/solved-how-to-log-the-duration-of-a-key-press and http://forum.cogsci.nl/index.php?p=/discussion/1199/solved-log-time-and-duration-of-multiple-key-presses
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,
Satrio

Comments

  • eduardeduard Posts: 977

    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 = pygame.key.name(event.key)
                     var.respTime = clock.time()
                     keydown = False
                     keyup = True
        if clock.time()-t0 > timeout: 
            break
    log.write_vars()
    

    Hope this helps.

    Eduard

    Thanked by 1satriopriyo
  • 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,
    Satrio

Sign In or Register to comment.