aboutsummaryrefslogtreecommitdiff
path: root/win32.py
diff options
context:
space:
mode:
Diffstat (limited to 'win32.py')
-rwxr-xr-xwin32.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/win32.py b/win32.py
index 46d1efe..bff980b 100755
--- a/win32.py
+++ b/win32.py
@@ -1,6 +1,6 @@
# Required for the window title name
from ctypes import wintypes, windll, create_unicode_buffer, WINFUNCTYPE
-from typing import Self, Optional, Dict
+from typing import Optional, Dict
from zope import interface
from interfaces import desktopEvent
@@ -51,12 +51,12 @@ def setHook(WinEventProc, eventType):
@interface.implementer(desktopEvent.IDesktop)
class Listener(object):
- def __init__(self: Self, mapping: Dict[str, str], queue):
+ def __init__(self, mapping: Dict[str, str], queue):
self.WinEventProc = WinEventProcType(self.callback)
self.mapping = mapping
self.queue = queue
- def getForegroundWindowTitle(self: Self) -> Optional[str]:
+ def getForegroundWindowTitle(self) -> Optional[str]:
""" Get the window title name.
Example found from https://stackoverflow.com/a/58355052
See the function in the winuser librarry :
@@ -73,7 +73,7 @@ class Listener(object):
else:
return None
- def callback(self: Self, hWinEventHook, event, hwnd, idObject, idChild, dwEventThread,
+ def callback(self, hWinEventHook, event, hwnd, idObject, idChild, dwEventThread,
dwmsEventTime) -> None:
if hwnd != windll.user32.GetForegroundWindow():
@@ -88,17 +88,21 @@ class Listener(object):
return
title = str(title.value).lower()
for pattern, code in self.mapping.items():
+ if pattern == "default":
+ continue
if pattern in title:
self.queue.put ( (code, None) )
return
- self.queue.put ( ("Windows", None) )
+ default = self.mapping.get("default", None)
+ if default is not None:
+ self.queue.put ( (default, None) )
- def start(self: Self) -> None:
+ def start(self) -> None:
self.hookIDs = [setHook(self.WinEventProc, et) for et in eventTypes.keys()]
if not any(self.hookIDs):
print('SetWinEventHook failed')
sys.exit(1)
- def stop(self: Self) -> None:
+ def stop(self) -> None:
for hook in self.hookIDs:
windll.user32.UnhookWinEvent(hook)