WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Detecting Window Focus (https://forum.worldviz.com/showthread.php?t=3981)

nabrahamson 11-01-2011 10:19 AM

Detecting Window Focus
 
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:
Code:

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.


All times are GMT -7. The time now is 01:46 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC