Make a routine end only if the two allowed keys are pressed simultaneously

Hi,
I am trying to make a routine end only if the two allowed keys are pressed simultaneously. Maybe someone has an idea, how to do it.

I tried to include the following code under the “Each Frame” rider (based on the proposal here Keyboard - several keys pressed simultaneously - Coding - PsychoPy :

stime = core.getTime()
while core.getTime() - stime < 5:
   key_events = event.getKeys()
    if len(key_events) > 0:
      continueRoutine = False

However, with the solution above it looks like after a certain time has lapsed the routine ends also if only one of the keys is pressed. What might be wrong with this code?