Keyboard press: when holding a buttom I need a response when pressend and another when released

Hi everyone!
I’m doing an experiment in Psychopy using Python.
I have a problem: I want to ask my subjects to hold the spacebar and as soon as they press I want the windows screen to change and when they release that I want the windows screen to change once more.
I tried to read the documentation and I can only find event.getKeys, but I dont know if I can set I want to record the two answers. I’m trying the code below, but sometimes it works, sometimes it doesn’t.

win = visual.Window(
size = [1920,1080],
monitor=“testMonitor”,
color=‘black’,
units=‘norm’,
fullscr = False
)
intro = visual.TextStim(win, height=0.09, font= “Arial”)
intro.text = “ciao”

intro.draw()
win.flip()

lista=[ ]
intro_loop = True
while intro_loop:
intro_keys = kb.getKeys([“s”], waitRelease=True)
if key.is_pressed(‘s’):
if len(lista)==0:
lista.append(“1”)
if len(lista)==1:
intro.text=“hello world!”
intro.draw()
win.flip()

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

Thanks everyone!