Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

win32gui.SetActiveWindow() ERROR : The specified procedure could not be found

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!

like image 588
Wise Avatar asked Jan 12 '13 16:01

Wise


1 Answers

This also worked for me

import win32gui, win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('%')
win32gui.SetForegroundWindow(window.hwnd)
like image 102
Natty Avatar answered Oct 16 '22 07:10

Natty