What version of the engine are you working on?
UE 4 would exit game mode on esc, UE5 needs a combination for it to trigger
Try packing your game or running it in standalone game mode and see if it triggers there.
What exact logic is called on escape? Could it be that your game is quitting before you trigger the callback? Please post some more in depth information on the function you are trying to get working.