From fcce9177e356bb27283926451433130a8809fcb0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 27 Aug 2023 16:41:10 +0200 Subject: Send the whole keymap to the device --- win32.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'win32.py') 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) -- cgit v1.2.3