Ignore ESC when App not active window

I have my App set up to capture the ESC key and do various things when encountered. However, the app still captures the ESC and tries to execute when I am working in another app. Is there a way to limit it to only when the app is the active window?

Store a flag within the App events Activate and Deactivate.