Using a keypress in a staircase

OS (e.g. Win10): Big Sur 11.1
PsychoPy version (e.g. 1.84.x): 2020.2.10
Standard Standalone? (y/n) Yes
What are you trying to achieve?:
I am trying to build a staircase through code components that change the height or width of an image depending on the keypress. This worked using a code component when one image is presented. The issue is that I am presenting a drifting grating meaning that a trial presents ~10 sequential images at a fast rate. When I add the loop that presents all 10 images it causes my keyboard component to not work well with my staircase. This (I think?) is because the keypress is overwritten each time through the loop. So when the staircase checks for the keypress it thinks nothing was pressed because that is the input of the last loop iteration. How do I make a keyboard component that checks and records a keypress at any point during the loop? Currently, my staircase is in a second routine that just has a code that checks if key_resp.keys==corrAns and adjusts a variable assigned to the height and width of the image. I also tried using the if statement if any(corrAns in s for s in key_resp.keys): but this just gave me the error “TypeError: argument of type ‘NoneType’ is not iterable”