diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2023-08-27 16:41:10 +0200 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2023-08-27 16:41:10 +0200 |
commit | fcce9177e356bb27283926451433130a8809fcb0 (patch) | |
tree | ff1aecf99be053f1681bd8965ae3f33c2a42169f /win32.py | |
parent | 02d676bda89c2fb8469ea81f7429c19c1e29df7c (diff) |
Send the whole keymap to the device
Diffstat (limited to 'win32.py')
-rwxr-xr-x | win32.py | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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)
|