aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2024-07-05 09:55:29 +0200
committerSébastien Dailly <sebastien@chimrod.com>2024-07-05 09:55:29 +0200
commit463acffe16ead0b345ba48cd6c9c94713974185c (patch)
treeac98390ed729fdfdcb52723f967d73452ddc7796
parent784af6cab0bc195c5c53a6f08bd30fda1f15f977 (diff)
Updated the windows handler
-rwxr-xr-xwin32.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/win32.py b/win32.py
index ee146e6..44cee5c 100755
--- a/win32.py
+++ b/win32.py
@@ -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) )