There is no way unless you hijack the back button from the OS and have it broadcast to wake up your app's PopupWindow (I do not suggest doing this).
You should override onBackPressed() or I believe onKeyDown(int keyCode, KeyEvent event) in your Activity to act on/consume the back key (while your activity is in the foreground). As far as having it execute something "dynamic", I'm not exactly sure I understand what you are asking. You can have the code in your PopupWindow class, but call it from onBackPressed() or onKeyDown() through your instance variable in your activity.