Display of a stimulus as long as a key is pressed not working online

Hi everyone,

I’m trying to display a sound component as long as a key is pressed (i.e., while the person press the space bar the sound is played and stop when the space bar is release)

It’s perfectly working offline where I have two keyboard components linked to one another

pressed_keys = key_resp.keys

if 'space' in pressed_keys:
    appearance = 1

and so the second component start, and the trial stop when the bar is release

When pushing it to pavlovia it doesn’t work: instead of the stimulus appearing for as long as the space bar is pressed, I need to double click (one click to make it appear one click to make it disappear).
Any idea how to make it appear as long as the bar is press online?

Thanks in advance!

I would use.

if key_resp.keys:
     is 'space' in key_resp.keys:
          appearance = 1

Ok thanks, and would this make it work online? Because currently it’s only working offline but when push on Pavlovia instead of the stimulus being presented as long as the space bar is pressed I need to click one to make it appear and reclick to make it disappear