Change opacity on button press

Hi all, I am new to psychopy and I am trying to change opacity of an image every time there is a space bar press. I am using the custom code component and am having issues updating the image. I am not sure if it’s a key board issue or something else.

I have a keyboard component titled ‘work_for_feedback_space_bar_press’ that is set to a duration of 2.5 seconds. Below this, I have a custom code component with the following code:

Begin Routine:
feedback_stim_to_draw.pos = (0,0)
grey_no_feedback_stim.pos = (0,0)

feedback_stim_to_draw.opacity = 1
grey_no_feedback_stim.opacity = 1

current_opacity = []
update_opacity = .0150

Each Frame:

feedback_stim_to_draw.setAutoDraw(True)
grey_no_feedback_stim.setAutoDraw(True)

if work_for_feedback_space_bar_press.getKeys(['space']):
    
    grey_no_feedback_stim.opacity = grey_no_feedback_stim.opacity - update_opacity

Thank you!

Also I should add that - Currently, the routine is starting and then the transparency is being repeatedly reduced without me making any button presses.