Howdy, Stranger!

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

Supported by

Keyboard response, a second too much?

edited February 2017 in OpenSesame

Hello guys,
I wrote a script which has to do the following things:
1. play a sound and wait for 3.5 seconds
2. after these 3.5 seconds, wait for the operator to press a key with a time window of 4 seconds. Instead of proceeding after the keypress, wait the whole 4 seconds.
3. repeat step 1 and 2 for a certain amount of times

My script for that:

def sound_play():

j=1
while j<11:
    sound = "0" + str(j) + "_Set1_einfach_3.5sec.wav"
    src = pool[sound]
    my_sampler = sampler(src, volume=1)
    my_sampler.play()
    t1=time.clock()
    #print(t1)
    j=j + 1
    self.sleep(3500)

    start_time = time.clock() * 1000
    key_response = keyboard(keylist = ['a'], timeout=4000)
    key, end_time = key_response.get_key()
    #end_time = end_time - 1000
    var.response = key
    var.response_time = end_time - start_time
    diff = 4000 - int(var.response_time)
    clock.sleep(diff)
return

the following problem appaers: when the operator presses 'a' immidiatly after the 3.5 seconds of soundplaying there is still a response_time of >1000 milliseconds. I found out that the end_time I get from get_key() is one second more than it should be but I don't know why?! Fixing it by just subtracting 1000 ms from end_time semms not right for me.

Do you guys have any idea?
Thanks a lot!

Comments

Sign In or Register to comment.