| Reference | Downloads | Github

Recording infants looking time

Hi all,

We want to write a code that records the duration of infants looking behaviour when they look at a fixed image on the left or right of the screen.

A trial starts with an image on the left or right screen, and we play a continuous stream of auditory samples until the infant looks away 2s.

We want to record the infant attention to the stimulus; however, we want to move subsequent trial if the infant looked away more than 2s.

We use the ‘up’ key to record looking behaviour, but there is a problem between actual time because it does not look normal. Please see the message I got when I ran the study.

########### Running: C:\Users\Infant Lab\Desktop\HSs\ ###########

17014.4448 INFO Loaded monitor calibration from [‘2021_05_18 12:31’]

pygame 1.9.6

Hello from the pygame community.

up 268626.6679573 0.7888032999471761


up 268630.5078914 4.628737399994861


up 268634.8439907 8.964836700004525


up 268638.131816 12.252661999955308


up 268641.507716 15.628561999998055


up 268644.3395635 18.460409499995876



My supervisor has kindly helped me writing the code, but I assume there is a problem between actual time and recording time.

Please see the code below and help me to fix it.

Begin Experiment
from psychopy.hardware import keyboard


Begin Routine

Each Frame
keys=kb.getKeys(['up'], waitRelease=False)

for thisKey in keys:
print(, thisKey.tDown, thisKey.rt)
if thisKey.tDown - clock.getAbsTime() >2:

Many thanks in advance.


Please use triple backticks to format text as code. This makes the post much more readable.
print(‘Hello World’)

… yields:

print('Hello World')

When you use waitRelease=False, can you not use thisKey.duration to find the duration of a keypress? Check docs.

Thanks for your reply @filiabel. I will use them and work on the coding.

1 Like

The next release of psychopy (should be coming out in a matter of hours, if all goes well) will include eyetracker support in Builder and a component (:roi: Region Of Interest) which does exactly what you describe - progresses the experiment when the participant looks at / away from an area. As with any .0 release, approach with caution and keep an eye out for bug fix releases over the next few weeks, but I think this will make what you’re trying to do a lot simpler :slight_smile:

Hi @TParsons,

That’s good to know, and I hope it won’t take long :crossed_fingers:
I must work on the coding with the current one.

Best wishes,

1 Like