How to watch for a keypress in a macro for some time?

I want to make a macro that would do something, in my case it would do some keystrokes :

And then I wish it would listen for a return keystroke for some time and if it is pressed activate esc, if not do nothing.

My use case is that I want to activate a prefilled search, then make the search and when I press return on the search, do escape key as well. If I don’t however or change my mind, nothing should happen and it should stop listening to keystrokes.

I am kind of confused how to make it happen.

Thank you for any help.

I’ll take a shot.
set the “Set Action Timeout…” to your ‘some time’ on the ‘if all conditions’ step.
ie. 2 minutes or what ever you like.
Then after that step put a
If
Variable Last_Action contains Action timeout exceeded
then
nothing
else
xxx

I can't find Set Action Timeout in actions :

Nor in the if conditions :

In the wiki it says it's an action :

https://wiki.keyboardmaestro.com/manual/Menus?s[]=action&s[]=timeout#Set_Action_Timeout

A bit confused by this.

I was thinking I could use a for loop here. Make an action block that would run for 5 seconds and in there watch for return keystroke. And then quit macro running once time is up or return key was pressed.

Under the 'gear' icon of the step.
Set that timeout to the time you want to wait.
Be sure to UN check 'timeout aborts macro'
Then set the next step to be the set variable xxxx to
%ActionResult%
Base your next step on the variable xxxx
If = OK (or Action Timeout exceeded) then action A
else
action B

@nikivi, as usual, search is your friend. :wink:
KM Wiki Search: action timeout

KM Editor Help Search:

Also, I have posted several examples in this forum of how to use a Pause Until to wait on a keystroke. Please do some searching and you will find them.