Sounds like AutoIT may be the better solution. No experience with it but worthy of further investigation.

I have tried working with SetFocus() but depending on the modality of the window, often could not detect the specific window in order to deal with it.

Correct me if I'm wrong, but if the window is application modal, SetFocus() cannot detect it but can detect only the parent application's window. At least that's been my experience FWIW.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.