Howdy, Stranger!

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

Supported by

Showing a stimuli while a button is presssed and measuring the pressing time

HI,

I am attempting to create an experiment in which a stimulus

would appear the moment that the participants press a button and disappear the

moment that they let it go. Further, I want to measure the duration that the participants

pressed the button.

I have already gotten some code to measure for how long the participants

pressed the button:


import pygame
from pygame.locals import *
key_down_time = None
while key_down_time == None:
for event in pygame.event.get():
if event.type == KEYDOWN:
key_down_time = self.time()
key_pressed = event.key
break
key_up_time = None
while key_up_time == None:
for event in pygame.event.get():
if event.type == KEYUP:
key_up_time = self.time()
break
key_duration = key_up_time - key_down_time
self.experiment.set("key_duration", key_duration) 


but I do not know how to use it to present the stimuli.

Could someone help?

Comments

  • Hi,

    That should be easy. Just prepare two canvasses one with the image and one without.

    Then in your loop you can show the first canvas for keydown events, and the second image for keyup events. Does that make sense?

    Eduard

    ps. when you post code, make sure you use the right indentation, otherwise it is very difficult to see what your code is supposed to do.

    Buy Me A Coffee

Sign In or Register to comment.