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

Press and hold key for set duration before continuing sequence

Hi there,

I'm new to OpenSesame and Python but I've been asking some progress with a few threads and the key release is working fine but I'm having some trouble setting a 'press and hold' response that is needed to start the sequence.

The experiment is quite simple:

  1. Participant has to press and hold a key for 1000ms
  2. Three discs appear on the screen
  3. One of the disk turns green, release the button press, and make a reaching motion to touch the location on the touchscreen

I am struggling to set the press and hold response. I've searched the topics from a similar topic and I was trying to figure out a way to adapt this inline from an earlier topic:

I just don't have enough knowledge of python to know how to go about it.

Any help is much appreciated.



  • sebastiaansebastiaan Posts: 2,856


    The problem with your script is the indentation, i.e. the number of tabs that precede each line. The break statement should be intended one step down, so that it's not in the else block. Does that make sense? Like this:

    import pygame
    while True:
        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:

    An equivalent code that is perhaps easier to read would be:

    import pygame
    while not any(event.type == pygame.KEYDOWN for event in pygame.event.get()):

    To learn a bit more about loops, check out this video:


    There's much bigger issues in the world, I know. But I first have to take care of the world I know.

Sign In or Register to comment.