Psychopy in python : having two answers once when the key is pressed and the second when is released

Viewed 47

I need to modify a script in psychopy. The thing I need is the subject to press and hold a buttom in the keyboard, but I'd like to have two responses: one when he/her presses it (and the windows with text has to change), and the second when he/her releases it (and the windows with text has to change again). I am using event.getKeys function of psychopy, and then I'm using keyboard library. after inizializing the window screen and the text and importing psychopy and the functions I need and keyboard library as key.

intro.draw()
win.flip() # reset the clock to record a response time and clear events
event.clearEvents('all')
event.globalKeys.clear()  #to avoid problems with the keys you pressed before

intro_loop = True
while intro_loop:
    intro_keys = kb.getKeys(["space"], waitRelease=True)
    if key.is_pressed('space'): 
         intro.text = 'Hi, please follow these instructions :) '
         intro.draw()
         win.flip() # reset the clock to record a response time and clear events

    if len(intro_keys):
            win.close()
            intro_loop = False

I did the same in another script (just to try) but instead of having a window text screen I printed two different things, and it worked. in this script, instead, it completely ignores the function "key.is_pressed". do you have any ideas?

0 Answers
Related