View Full Version : Detecting Window Focus
nabrahamson
11-01-2011, 10:19 AM
Is there a native way in Vizard to detect if a windowed application has focus? I am trying to prevent user input events from being passed through to other windows applications, and I would like to have a method to tell the computer to stop listening to the input device when the Vizard window doesn't have focus.
farshizzo
11-01-2011, 10:46 AM
You can use the win32gui.GetForegroundWindow function to get a handle to the active window. You can check this handle against the Vizard window handle to determine whether Vizard has focus:import win32gui
def VizardHasFocus():
return win32gui.GetForegroundWindow() == viz.window.getHandle()
if VizardHasFocus():
print 'Vizard has focus'
else:
print 'Vizard does not have focus'
nabrahamson
11-01-2011, 11:45 AM
Thank you. I will give that a try.
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.