I would like to implement an interactive function that, in the "canonical" case, selects the window that was selected before the currently selected one1.
But my plan founders immediately on this question: how can my future function find out, to begin with, what the previously selected window is???
1 There are a few edge cases, e.g. when no other window was previously selected, that I won't get into.
C-h i g(elisp)Selecting windowshas some information that might be helpful.