diff options
Diffstat (limited to 'win32.py')
-rwxr-xr-x | win32.py | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -4,21 +4,24 @@ from typing import Optional, Dict from zope import interface
from interfaces import desktopEvent
+import win32api
+import win32gui
+import win32con
+from zope import component
+from interfaces.message import IMessage, Debug
# This code tries to hook the Focus changes events with the callback method.
# The types of events we want to listen for, and the names we'll use for
# them in the log output. Pick from
# http://msdn.microsoft.com/en-us/library/windows/desktop/dd318066(v=vs.85).aspx
-EVENT_OBJECT_FOCUS = 0x8005
-EVENT_OBJECT_NAMECHANGE = 0x800C
WINEVENT_OUTOFCONTEXT = 0x0000
eventTypes = {
#win32con.EVENT_SYSTEM_FOREGROUND: "Foreground",
- EVENT_OBJECT_FOCUS: "Focus",
- EVENT_OBJECT_NAMECHANGE: "NameChange",
- #win32con.EVENT_OBJECT_SHOW: "Show",
+ win32con.EVENT_OBJECT_FOCUS: "Focus",
+ win32con.EVENT_OBJECT_NAMECHANGE: "NameChange",
+ win32con.EVENT_OBJECT_SHOW: "Show",
#win32con.EVENT_SYSTEM_DIALOGSTART: "Dialog",
#win32con.EVENT_SYSTEM_CAPTURESTART: "Capture",
#win32con.EVENT_SYSTEM_MINIMIZEEND: "UnMinimize"
@@ -76,9 +79,7 @@ class Listener(object): def callback(self, hWinEventHook, event, hwnd, idObject, idChild, dwEventThread,
dwmsEventTime) -> None:
- if hwnd != windll.user32.GetForegroundWindow():
- # Only check the active window, the events received from other
- # windows are ignored.
+ if hwnd is None:
return
length = windll.user32.GetWindowTextLengthW(hwnd)
@@ -87,13 +88,16 @@ class Listener(object): if title.value is None:
return
title = str(title.value).lower()
- for pattern in reversed(self.mapping):
+ if title == "":
+ return
+ for pattern, code in self.mapping.items():
if pattern == "default":
continue
if pattern in title:
- code = self.mapping[pattern]
self.queue.put ( (code, None) )
return
+ print("Matching '%s' to default" % title)
+ # Get the default mapping to apply if there is any defined
default = self.mapping.get("default", None)
if default is not None:
self.queue.put ( (default, None) )
|