(背景) やりたいこと 答え 参考 おわりに (背景) やりたいこと ウィンドウハンドル hwnd に対し、activate(hwnd) を実行すると、hwnd が確実にアクティブ(Altabで選択した時の状態)になる……このような activate 関数を実装したい。 Windows 7 を想定。 答え AttachThreadInput → BringWindowToTop をした後に、当該ウィンドウの左上をクリックする というやり方にした。 ソース(一部オレオレライブラリがあるけど割愛): def activate_by_click(target_hwnd): rect = windowlib.GetWindowRect(target_hwnd) curmx, curmy = mouselib.get_cursorpos() mouselib.set_cursorpos(rect.x