本文整理汇总了Python中winUser.getForegroundWindow函数的典型用法代码示例。如果您正苦于以下问题:Python getForegroundWindow函数的具体用法?Python getForegroundWindow怎么用?Python getForegroundWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getForegroundWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: event_valueChange
def event_valueChange(self):
global lastMSNHistoryValue
if winUser.isDescendantWindow(winUser.getForegroundWindow(),self.windowHandle):
value=self.value
if value!=lastMSNHistoryValue and config.conf["presentation"]["reportDynamicContentChanges"]:
speech.speakText(value)
lastMSNHistoryValue=value
示例2: event_gainFocus
def event_gainFocus(vmID,accContext):
tempContext=accContext
while tempContext:
try:
tempContext=bridgeDll.getActiveDescendent(vmID,tempContext)
except:
tempContext=None
try:
depth=bridgeDll.getObjectDepth(vmID,tempContext)
except:
depth=-1
if tempContext and (depth<=0 or bridgeDll.isSameObject(vmID,accContext,tempContext)):
tempContext=None
if tempContext:
bridgeDll.releaseJavaObject(vmID,accContext)
accContext=tempContext
jabContext=JABContext(vmID=vmID,accContext=accContext)
if not winUser.isDescendantWindow(winUser.getForegroundWindow(),jabContext.hwnd):
return
focus=eventHandler.lastQueuedFocusObject
if (isinstance(focus,NVDAObjects.JAB.JAB) and focus.jabContext==jabContext):
return
obj=NVDAObjects.JAB.JAB(jabContext=jabContext)
if obj.role==controlTypes.ROLE_UNKNOWN:
return
eventHandler.queueEvent("gainFocus",obj)
示例3: pumpAll
def pumpAll():
global _deferUntilForegroundWindow,_foregroundDefers
if _deferUntilForegroundWindow:
# #3831: Sometimes, a foreground event is fired,
# but GetForegroundWindow() takes a short while to return this new foreground.
if _foregroundDefers<MAX_FOREGROUND_DEFERS and winUser.getForegroundWindow()!=_deferUntilForegroundWindow:
# Wait a core cycle before handling events to give the foreground window time to update.
core.requestPump()
_foregroundDefers+=1
return
else:
# Either the foreground window is now correct
# or we've already had the maximum number of defers.
# (Sometimes, foreground events are fired even when the foreground hasn't actually changed.)
_deferUntilForegroundWindow=None
#Receive all the winEvents from the limiter for this cycle
winEvents=winEventLimiter.flushEvents()
focusWinEvents=[]
validFocus=False
fakeFocusEvent=None
for winEvent in winEvents[0-MAX_WINEVENTS:]:
# #4001: Ideally, we'd call shouldAcceptEvent in winEventCallback,
# but this causes focus issues when starting applications.
if not eventHandler.shouldAcceptEvent(winEventIDsToNVDAEventNames[winEvent[0]], windowHandle=winEvent[1]):
continue
#We want to only pass on one focus event to NVDA, but we always want to use the most recent possible one
if winEvent[0] in (winUser.EVENT_OBJECT_FOCUS,winUser.EVENT_SYSTEM_FOREGROUND):
focusWinEvents.append(winEvent)
continue
else:
for focusWinEvent in reversed(focusWinEvents):
procFunc=processForegroundWinEvent if focusWinEvent[0]==winUser.EVENT_SYSTEM_FOREGROUND else processFocusWinEvent
if procFunc(*(focusWinEvent[1:])):
validFocus=True
break
focusWinEvents=[]
if winEvent[0]==winUser.EVENT_SYSTEM_DESKTOPSWITCH:
processDesktopSwitchWinEvent(*winEvent[1:])
elif winEvent[0]==winUser.EVENT_OBJECT_SHOW:
processShowWinEvent(*winEvent[1:])
elif winEvent[0] in MENU_EVENTIDS+(winUser.EVENT_SYSTEM_SWITCHEND,):
# If there is no valid focus event, we may need to use this to fake the focus later.
fakeFocusEvent=winEvent
else:
processGenericWinEvent(*winEvent)
for focusWinEvent in reversed(focusWinEvents):
procFunc=processForegroundWinEvent if focusWinEvent[0]==winUser.EVENT_SYSTEM_FOREGROUND else processFocusWinEvent
if procFunc(*(focusWinEvent[1:])):
validFocus=True
break
if fakeFocusEvent:
# Try this as a last resort.
if fakeFocusEvent[0] in (winUser.EVENT_SYSTEM_MENUSTART, winUser.EVENT_SYSTEM_MENUPOPUPSTART):
# menuStart needs to be handled specially and might act even if there was a valid focus event.
processMenuStartWinEvent(*fakeFocusEvent, validFocus=validFocus)
elif not validFocus:
# Other fake focus events only need to be handled if there was no valid focus event.
processFakeFocusWinEvent(*fakeFocusEvent)
示例4: postPopup
def postPopup(self):
"""Clean up after a popup dialog or menu.
This should be called after a dialog or menu was popped up for the user.
"""
if not winUser.isWindowVisible(winUser.getForegroundWindow()):
# The current foreground window is invisible, so we want to return to the previous foreground window.
# Showing and hiding our main window seems to achieve this.
self.Show()
self.Hide()
示例5: prePopup
def prePopup(self):
"""Prepare for a popup.
This should be called before any dialog or menu which should pop up for the user.
L{postPopup} should be called after the dialog or menu has been shown.
@postcondition: A dialog or menu may be shown.
"""
if winUser.getWindowThreadProcessID(winUser.getForegroundWindow())[0] != os.getpid():
# This process is not the foreground process, so bring it to the foreground.
self.Raise()
示例6: event_gainFocus
def event_gainFocus(vmID,accContext,hwnd):
jabContext=JABContext(hwnd=hwnd,vmID=vmID,accContext=accContext)
if not winUser.isDescendantWindow(winUser.getForegroundWindow(),jabContext.hwnd):
return
focus=eventHandler.lastQueuedFocusObject
if (isinstance(focus,NVDAObjects.JAB.JAB) and focus.jabContext==jabContext):
return
obj=NVDAObjects.JAB.JAB(jabContext=jabContext)
if obj.role==controlTypes.ROLE_UNKNOWN:
return
eventHandler.queueEvent("gainFocus",obj)
示例7: shouldAcceptEvent
def shouldAcceptEvent(eventName, windowHandle=None):
"""Check whether an event should be accepted from a platform API.
Creating NVDAObjects and executing events can be expensive
and might block the main thread noticeably if the object is slow to respond.
Therefore, this should be used before NVDAObject creation to filter out any unnecessary events.
A platform API handler may do its own filtering before this.
"""
if not windowHandle:
# We can't filter without a window handle.
return True
key = (eventName,
winUser.getWindowThreadProcessID(windowHandle)[0],
winUser.getClassName(windowHandle))
if key in _acceptEvents:
return True
if eventName == "valueChange" and config.conf["presentation"]["progressBarUpdates"]["reportBackgroundProgressBars"]:
return True
if eventName == "show":
# Only accept 'show' events for specific cases, as otherwise we get flooded.
return winUser.getClassName(windowHandle) in (
"Frame Notification Bar", # notification bars
"tooltips_class32", # tooltips
"mscandui21.candidate", "mscandui40.candidate", "MSCandUIWindow_Candidate", # IMM candidates
"TTrayAlert", # 5405: Skype
)
if eventName == "reorder":
# Prevent another flood risk.
return winUser.getClassName(windowHandle) == "TTrayAlert" # #4841: Skype
if eventName == "alert" and winUser.getClassName(winUser.getAncestor(windowHandle, winUser.GA_PARENT)) == "ToastChildWindowClass":
# Toast notifications.
return True
if eventName in ("menuEnd", "switchEnd", "desktopSwitch"):
# #5302, #5462: These events can be fired on the desktop window
# or windows that would otherwise be blocked.
# Platform API handlers will translate these events to focus events anyway,
# so we must allow them here.
return True
if windowHandle == winUser.getDesktopWindow():
# #5595: Events for the cursor get mapped to the desktop window.
return True
fg = winUser.getForegroundWindow()
if (winUser.isDescendantWindow(fg, windowHandle)
# #3899, #3905: Covers cases such as the Firefox Page Bookmarked window and OpenOffice/LibreOffice context menus.
or winUser.isDescendantWindow(fg, winUser.getAncestor(windowHandle, winUser.GA_ROOTOWNER))):
# This is for the foreground application.
return True
if (winUser.user32.GetWindowLongW(windowHandle, winUser.GWL_EXSTYLE) & winUser.WS_EX_TOPMOST
or winUser.user32.GetWindowLongW(winUser.getAncestor(windowHandle, winUser.GA_ROOT), winUser.GWL_EXSTYLE) & winUser.WS_EX_TOPMOST):
# This window or its root is a topmost window.
# This includes menus, combo box pop-ups and the task switching list.
return True
return False
示例8: prePopup
def prePopup(self):
"""Prepare for a popup.
This should be called before any dialog or menu which should pop up for the user.
L{postPopup} should be called after the dialog or menu has been shown.
@postcondition: A dialog or menu may be shown.
"""
nvdaPid = os.getpid()
focus = api.getFocusObject()
if focus.processID != nvdaPid:
self.prevFocus = focus
self.prevFocusAncestors = api.getFocusAncestors()
if winUser.getWindowThreadProcessID(winUser.getForegroundWindow())[0] != nvdaPid:
# This process is not the foreground process, so bring it to the foreground.
self.Raise()
示例9: kwargsFromSuper
def kwargsFromSuper(cls,kwargs,relation=None):
windowHandle=None
if relation in ('focus','foreground'):
windowHandle=winUser.getForegroundWindow()
if not windowHandle: windowHandle=winUser.getDesktopWindow()
if windowHandle and relation=="focus":
threadID=winUser.getWindowThreadProcessID(windowHandle)[1]
threadInfo=winUser.getGUIThreadInfo(threadID)
if threadInfo.hwndFocus: windowHandle=threadInfo.hwndFocus
elif isinstance(relation,tuple):
windowHandle=_windowFromPoint(ctypes.wintypes.POINT(relation[0],relation[1]))
if not windowHandle:
return False
kwargs['windowHandle']=windowHandle
return True
示例10: processFocusWinEvent
def processFocusWinEvent(window,objectID,childID,force=False):
"""checks to see if the focus win event is not the same as the existing focus,
then converts the win event to an NVDA event (instanciating an NVDA Object) then calls processFocusNVDAEvent. If all is ok it returns True.
@type window: integer
@param objectID: a win event's object ID
@type objectID: integer
@param childID: a win event's child ID
@type childID: integer
@param force: If True, the shouldAllowIAccessibleFocusEvent property of the object is ignored.
@type force: boolean
@returns: True if the focus is valid and was handled, False otherwise.
@rtype: boolean
"""
windowClassName=winUser.getClassName(window)
# Generally, we must ignore focus on child windows of SDM windows as we only want the SDM MSAA events.
# However, we don't want to ignore focus if the child ID isn't 0,
# as this is a child control and the SDM MSAA events don't handle child controls.
if childID==0 and not windowClassName.startswith('bosa_sdm') and winUser.getClassName(winUser.getAncestor(window,winUser.GA_PARENT)).startswith('bosa_sdm'):
return False
rootWindow=winUser.getAncestor(window,winUser.GA_ROOT)
# If this window is not within the foreground window and this window or its root window is not a popup window, and this window's root window is not the highest in the z-order
if not winUser.isDescendantWindow(winUser.getForegroundWindow(),window) and not (winUser.getWindowStyle(window) & winUser.WS_POPUP or winUser.getWindowStyle(rootWindow)&winUser.WS_POPUP) and winUser.getPreviousWindow(rootWindow)!=0:
# This is a focus event from a background window, so ignore it.
return False
#Notify appModuleHandler of this new foreground window
appModuleHandler.update(winUser.getWindowThreadProcessID(window)[0])
#If Java access bridge is running, and this is a java window, then pass it to java and forget about it
if JABHandler.isRunning and JABHandler.isJavaWindow(window):
JABHandler.event_enterJavaWindow(window)
return True
#Convert the win event to an NVDA event
NVDAEvent=winEventToNVDAEvent(winUser.EVENT_OBJECT_FOCUS,window,objectID,childID,useCache=False)
if not NVDAEvent:
return False
eventName,obj=NVDAEvent
if (childID==0 and obj.IAccessibleRole==oleacc.ROLE_SYSTEM_LIST) or (objectID==winUser.OBJID_CLIENT and "SysListView32" in obj.windowClassName):
# Some controls incorrectly fire focus on child ID 0, even when there is a child with focus.
try:
realChildID=obj.IAccessibleObject.accFocus
except:
realChildID=None
if isinstance(realChildID,int) and realChildID>0 and realChildID!=childID:
realObj=NVDAObjects.IAccessible.IAccessible(IAccessibleObject=obj.IAccessibleObject,IAccessibleChildID=realChildID,event_windowHandle=window,event_objectID=objectID,event_childID=realChildID)
if realObj:
obj=realObj
return processFocusNVDAEvent(obj,force=force)
示例11: processForegroundWinEvent
def processForegroundWinEvent(window,objectID,childID):
"""checks to see if the foreground win event is not the same as the existing focus or any of its parents,
then converts the win event to an NVDA event (instanciating an NVDA Object) and then checks the NVDAObject against the existing focus object.
If all is ok it queues the foreground event to NVDA and returns True.
@param window: a win event's window handle
@type window: integer
@param objectID: a win event's object ID
@type objectID: integer
@param childID: a win event's child ID
@type childID: integer
@returns: True if the foreground was processed, False otherwise.
@rtype: boolean
"""
#Ignore foreground events on windows that aren't the current foreground window
if window!=winUser.getForegroundWindow():
return False
# If there is a pending gainFocus, it will handle the foreground object.
oldFocus=eventHandler.lastQueuedFocusObject
#If this foreground win event's window is an ancestor of the existing focus's window, then ignore it
if isinstance(oldFocus,NVDAObjects.window.Window) and winUser.isDescendantWindow(window,oldFocus.windowHandle):
return False
#If the existing focus has the same win event params as these, then ignore this event
if isinstance(oldFocus,NVDAObjects.IAccessible.IAccessible) and window==oldFocus.event_windowHandle and objectID==oldFocus.event_objectID and childID==oldFocus.event_childID:
return False
#Notify appModuleHandler of this new foreground window
appModuleHandler.update(winUser.getWindowThreadProcessID(window)[0])
#If Java access bridge is running, and this is a java window, then pass it to java and forget about it
if JABHandler.isRunning and JABHandler.isJavaWindow(window):
JABHandler.event_enterJavaWindow(window)
return True
#Convert the win event to an NVDA event
NVDAEvent=winEventToNVDAEvent(winUser.EVENT_SYSTEM_FOREGROUND,window,objectID,childID,useCache=False)
if not NVDAEvent:
return False
eventHandler.queueEvent(*NVDAEvent)
return True
示例12: _get_isAlive
def _get_isAlive(self):
if self.isLoading:
return True
root=self.rootNVDAObject
if not root:
return False
if not winUser.isWindow(root.windowHandle):
return False
if root.appModule.appName.startswith('wwahost') and not winUser.isDescendantWindow(winUser.getForegroundWindow(),root.windowHandle):
# #4572: When a wwahost hosted app is in the background it gets suspended and all COM calls freeze.
# Therefore we don't have enough info to say whether its dead or not. We assume it is alive until we can get a better answer.
return True
try:
if not root.IAccessibleRole:
# The root object is dead.
return False
except watchdog.CallCancelled:
# #1831: If the root object isn't responding, treat the buffer as dead.
# Otherwise, we'll keep querying it on every focus change and freezing.
return False
states=root.states
if controlTypes.STATE_EDITABLE in states:
return False
return True
示例13: IsActive
def IsActive(self):
#4714: In wxPython 3, ProgressDialog.IsActive always seems to return False.
return winUser.isDescendantWindow(winUser.getForegroundWindow(), self.Handle)
示例14: _get_isInForeground
def _get_isInForeground(self):
fg=winUser.getForegroundWindow()
return self.windowHandle==fg or winUser.isDescendantWindow(fg,self.windowHandle)
示例15: shouldAcceptEvent
def shouldAcceptEvent(eventName, windowHandle=None):
"""Check whether an event should be accepted from a platform API.
Creating NVDAObjects and executing events can be expensive
and might block the main thread noticeably if the object is slow to respond.
Therefore, this should be used before NVDAObject creation to filter out any unnecessary events.
A platform API handler may do its own filtering before this.
"""
if not windowHandle:
# We can't filter without a window handle.
return True
wClass = winUser.getClassName(windowHandle)
key = (eventName,
winUser.getWindowThreadProcessID(windowHandle)[0],
wClass)
if key in _acceptEvents:
return True
if eventName == "valueChange" and config.conf["presentation"]["progressBarUpdates"]["reportBackgroundProgressBars"]:
return True
if eventName == "show":
# Only accept 'show' events for specific cases, as otherwise we get flooded.
return wClass in (
"Frame Notification Bar", # notification bars
"tooltips_class32", # tooltips
"mscandui21.candidate", "mscandui40.candidate", "MSCandUIWindow_Candidate", # IMM candidates
"TTrayAlert", # 5405: Skype
)
if eventName == "reorder":
# Prevent another flood risk.
return wClass == "TTrayAlert" # #4841: Skype
if eventName == "alert" and winUser.getClassName(winUser.getAncestor(windowHandle, winUser.GA_PARENT)) == "ToastChildWindowClass":
# Toast notifications.
return True
if eventName in ("menuEnd", "switchEnd", "desktopSwitch"):
# #5302, #5462: These events can be fired on the desktop window
# or windows that would otherwise be blocked.
# Platform API handlers will translate these events to focus events anyway,
# so we must allow them here.
return True
if windowHandle == winUser.getDesktopWindow():
# #5595: Events for the cursor get mapped to the desktop window.
return True
# #6713: Edge (and soon all UWP apps) will no longer have windows as descendants of the foreground window.
# However, it does look like they are always equal to or descendants of the "active" window of the input thread.
if wClass.startswith('Windows.UI.Core'):
gi=winUser.getGUIThreadInfo(0)
if winUser.isDescendantWindow(gi.hwndActive,windowHandle):
return True
fg = winUser.getForegroundWindow()
if wClass == "NetUIHWND" and winUser.getClassName(fg) == "Net UI Tool Window Layered":
# #5504: In Office >= 2013 with the ribbon showing only tabs,
# when a tab is expanded, the window we get from the focus object is incorrect.
# This window isn't beneath the foreground window,
# so our foreground application checks fail.
# Just compare the root owners.
if winUser.getAncestor(windowHandle, winUser.GA_ROOTOWNER) == winUser.getAncestor(fg, winUser.GA_ROOTOWNER):
return True
if (winUser.isDescendantWindow(fg, windowHandle)
# #3899, #3905: Covers cases such as the Firefox Page Bookmarked window and OpenOffice/LibreOffice context menus.
or winUser.isDescendantWindow(fg, winUser.getAncestor(windowHandle, winUser.GA_ROOTOWNER))):
# This is for the foreground application.
return True
if (winUser.user32.GetWindowLongW(windowHandle, winUser.GWL_EXSTYLE) & winUser.WS_EX_TOPMOST
or winUser.user32.GetWindowLongW(winUser.getAncestor(windowHandle, winUser.GA_ROOT), winUser.GWL_EXSTYLE) & winUser.WS_EX_TOPMOST):
# This window or its root is a topmost window.
# This includes menus, combo box pop-ups and the task switching list.
return True
return False