I get the active window like so:
window = win32gui.GetForegroundWindow()
which is an Int, say 1053634. And afterwards I try to set the foreground window back to the specified window:
win32gui.SetForegroundWindow(window)
And I get this error: win32gui.SetForegroundWindow(window) error: (127, 'SetForegroundWindow', 'The specified procedure could not be found.')
Sometimes when I do this in the interpreter, I get this error:
win32gui.SetForegroundWindow(1053634)
error: (0, 'SetForegroundWindow', 'No error message is available')
What do you think is the problem?
Thanks!
This also worked for me
import win32gui, win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('%')
win32gui.SetForegroundWindow(window.hwnd)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With