Howdy, Stranger!

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

Supported by

Keyboard response during sampler presentation

Hi there,

I have tried to read up on this topic through some of the other discussions but am finding myself lost in the details / other designs seem more complex. Basically, I need to collect a keyboard response (either S or D, where either S or D may be correct depending on the given trial) but this response needs to be collectable during the presentation phase as well as after. The design is structured as follows:

Here, the HF_D_1 loop runs the HF_sequence_1 sequence which contains the variable titled HF_sound (this involves six sound items which are then called in the sampler). The fixation dot is set at a duration 0 to run for the duration of the sequence, and then the sketchpad Recog_mid_1 displays '***' until the next sequence begins (HF_D_1R) - in this instance the second sequence is different to the first (hence D). This runs in the same manner as the last until a "Same/different?" sketchpad prompt appears (SD) also set at duration 0, to which the participant must press either S or D (set by the keyboard response titled End_HF_D_1).

This works well, but my problem is that I need to be able to record responses from the onset of HF_D_1R right up through the presentation of SD, rather than at the end only once SD appears. My understanding from other discussions is that I may need an inline script to do this but again, given the differences in designs I'm having trouble figuring out how to go about this. Any help is appreciated. Thank you!


  • Hi,

    Yes, inline_scripts might be to go-to solution. In the documentation you will see taht you can to all the things that you can do with [sketchpads]( and samplers also with inline_scripts and it is all that difficult. First, create canvasses , keyboard times, and load the sounds. Then, enter a loop in which you start waiting for key presses, depending on the time that has passed inside the loop you present either the one display, or the other, together with the corresponding sound.

    See for example here

    # create objects
    fix_cv = canvas()
    recog_cv = canvas()
    SD_cv = canvas()
    kb = keyboard(keylist = ['s','d','escape'])
    src = pool['sound.ogg']
    my_sampler = sampler(src, volume=.5)
    # draw the canvas, e.g.
    SD_cv.text("same or different")
    # define some times
    onset_firstFix = 1000
    onset_recogCv = 2000
    onset_secondFix = 3000
    onset_SDcv = 4000
    start_time = clock.time()
    while True: 
        k, t = kb.get_key(timeout=50)
        if k != None:
        if clock.time()-start_time > onset_SDcv:
        elif clock.time()-start_time > onset_secondFix:
        elif clock.time()-start_time > onset_recogCv:
        elif clock.time()-start_time > onset_firstFix:

    I haven't tested the script, but something along these lines should do the trick.

    Good luck,


Sign In or Register to comment.