Howdy, Stranger!

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

Supported by

Keyboard_Release and Response_Time collection

Hello everyone!

I'm trying to program an experiment, where an audiovisual stimulus will be displayed with a keyboard_release. (the pressing of the button will start the stimulus display, and its release will stop it).

I wrote the following code (I am a newbie at coding!) and everything runs correctly. My only problem is that I want to collect the following two variables: i)key_response and ii) rt (duration from the press until the release of the button). The first one is done, but I don't know how to collect the second one (I can only have the general timestamp). I would be greatful if anyone knows how I must write something like this in my code in order to get the keyboard_release duration.

my_keyboard = Keyboard()
    
exp.items["target_sampler"].prepare()
exp.items["target_sampler"].run()
exp.items["visual_letter"].prepare()
exp.items["visual_letter"].run()
response, timestamp = my_keyboard.get_key_release(timeout=8000)

items['target_sampler'].sampler.stop()

exp.set('response1', response)
exp.set('time1', timestamp)


Thanks in advance,

V.

Comments

  • Hi @Vassilis ,


    For someone who is new to programming you got quite far. :)


    To be able to calculate the duration of the keypress, you will also have to determine the time at which the key was pressed (instead of released) like so:


    # Get start time of the button press (timestamp1)
    var.response, var.timestamp1 = my_keyboard.get_key()
    
    # Get end time of the button press (release, timestamp2)
    var.response, var.timestamp2 = my_keyboard.get_key_release(timeout=8000)
    
    # Calculate the duration:
    var.duration = var.timestamp2 - var.timestamp1
    


    Is this what you were looking for?

    Also, note that you can set variables directly by using the var object (instead of the older exp.set() syntax).


    Hope this helps!


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Thank you Lotje for the immediate response!

    Everything runs perfectly with these few extra lines! Thanks again!

  • Great, thanks for letting us know! :)

    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.