Ooops, @gcjr beat me to it!
Anyway, what @gcjr says is exactly right, of course. Instead of putting a delay() between the two tests, you should use two states. You might call one state AWAITING_INPUT and the other state might be AWAITING_CONFIRMATION.
if (state == AWAITING_INPUT && input is active)
timestamp = millis() + 500
state = AWAITING_CONFIRMATION
else if (state == AWAITING_CONFIRMATION && millis() >= timestamp) //don't do this in real code
if (input is active)
do the important thing
else //input wasn't still active after 500ms, so abort
state = AWAITING_INPUT
Put that into a boolean function which you call repeatedly from loop(), and make that function return true (“do the important thing”) when the requirements are met, else return false.
Where I’ve said “don’t do this is real code” it’s because the test will fail if millis() rolls over. I’ve shown it this way because it’s easy to understand. @gcjr has shown the correct way to do it: compare intervals, not timestamps.
I haven’t attempted to show you how to do this using your example code at the top, because I’m hoping you will understand the basic principle, rather than having someone write the code for you.