adbsshdeck 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ """Windows: global hotkeys to stop scrcpy when the mirror steals focus (e.g. fullscreen)."""
2
+
3
+ import sys
4
+
5
+ SCRCPY_HOTKEY_ID = 0x4A42
6
+ SCRCPY_HOTKEY_ID2 = 0x4A43
7
+
8
+ _MOD_CONTROL = 0x0002
9
+ _MOD_ALT = 0x0001
10
+ _MOD_NOREPEAT = 0x4000
11
+ _VK_F12 = 0x7B
12
+ _VK_END = 0x23
13
+
14
+
15
+ def _register_one(hwnd: int, hid: int, vk: int) -> bool:
16
+ if sys.platform != "win32" or not hwnd:
17
+ return False
18
+ try:
19
+ import ctypes
20
+
21
+ return bool(
22
+ ctypes.windll.user32.RegisterHotKey(
23
+ int(hwnd), hid, _MOD_CONTROL | _MOD_ALT | _MOD_NOREPEAT, vk
24
+ )
25
+ )
26
+ except Exception:
27
+ return False
28
+
29
+
30
+ def register_scrcpy_stop_hotkey(hwnd: int) -> bool:
31
+ """Register Ctrl+Alt+F12 and Ctrl+Alt+End — either can stop the mirror from anywhere."""
32
+ ok_f12 = _register_one(hwnd, SCRCPY_HOTKEY_ID, _VK_F12)
33
+ ok_end = _register_one(hwnd, SCRCPY_HOTKEY_ID2, _VK_END)
34
+ return bool(ok_f12 or ok_end)
35
+
36
+
37
+ def unregister_scrcpy_stop_hotkey(hwnd: int) -> None:
38
+ if sys.platform != "win32":
39
+ return
40
+ try:
41
+ import ctypes
42
+
43
+ user32 = ctypes.windll.user32
44
+ user32.UnregisterHotKey(int(hwnd), SCRCPY_HOTKEY_ID)
45
+ user32.UnregisterHotKey(int(hwnd), SCRCPY_HOTKEY_ID2)
46
+ except Exception:
47
+ pass
48
+
49
+
50
+ def is_windows_hotkey_message(event_type, message) -> bool:
51
+ """Return True if this is WM_HOTKEY for one of our scrcpy stop ids."""
52
+ if sys.platform != "win32":
53
+ return False
54
+ try:
55
+ if hasattr(event_type, "data"):
56
+ et = bytes(event_type.data()).decode("latin1", errors="ignore")
57
+ else:
58
+ et = bytes(event_type).decode("latin1", errors="ignore")
59
+ except Exception:
60
+ try:
61
+ et = str(event_type)
62
+ except Exception:
63
+ return False
64
+ if "windows_generic_MSG" not in et and "windows_dispatcher_MSG" not in et:
65
+ return False
66
+ try:
67
+ import ctypes
68
+ from ctypes import wintypes
69
+
70
+ msg = ctypes.cast(int(message), ctypes.POINTER(wintypes.MSG)).contents
71
+ if msg.message != 0x0312:
72
+ return False
73
+ wp = int(msg.wParam)
74
+ return wp in (SCRCPY_HOTKEY_ID, SCRCPY_HOTKEY_ID2)
75
+ except Exception:
76
+ return False