How to see current window?

Is there a way with code I can in a general routine, which gets activated with CMD+P that shows the name of the window that was previously in focus? If so, how is this done?

Maybe another way to accomplish what I want is...If when you change focus of a window an event is posted in the now focused window gets control. In other words can the focused window tell it just got the focus. Is there way to do this?

How to see current window?
 
 
Q