ScreenMagnifier 1.11.0.post8__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.
Potentially problematic release.
This version of ScreenMagnifier might be problematic. Click here for more details.
- ScreenMagnifier/__init__.py +68 -0
- ScreenMagnifier/__main__.py +17 -0
- ScreenMagnifier/advancedoverlay.py +593 -0
- ScreenMagnifier/advancedpanel.py +521 -0
- ScreenMagnifier/analysiscontroller.py +533 -0
- ScreenMagnifier/analysisserver.py +404 -0
- ScreenMagnifier/colordetector/__init__.py +28 -0
- ScreenMagnifier/colordetector/colordetector.py +570 -0
- ScreenMagnifier/colordetector/core.py +434 -0
- ScreenMagnifier/colordetector/main.py +23 -0
- ScreenMagnifier/colordetector/mainwindow.py +182 -0
- ScreenMagnifier/colorpanel.py +424 -0
- ScreenMagnifier/colorswatches/__init__.py +16 -0
- ScreenMagnifier/colorswatches/colorswatches.py +316 -0
- ScreenMagnifier/colorswatches/main.py +23 -0
- ScreenMagnifier/colorswatches/mainwindow.py +60 -0
- ScreenMagnifier/controlpanel.py +234 -0
- ScreenMagnifier/detectionpanel.py +790 -0
- ScreenMagnifier/facedetector/__init__.py +24 -0
- ScreenMagnifier/facedetector/core.py +314 -0
- ScreenMagnifier/facedetector/facedetector.py +288 -0
- ScreenMagnifier/facedetector/main.py +23 -0
- ScreenMagnifier/facedetector/mainwindow.py +122 -0
- ScreenMagnifier/facedetector/models/__init__.py +4 -0
- ScreenMagnifier/facepointer.py +1121 -0
- ScreenMagnifier/features.py +50 -0
- ScreenMagnifier/hotkeys/__init__.py +16 -0
- ScreenMagnifier/hotkeys/hotkeys.py +379 -0
- ScreenMagnifier/hotkeys/main.py +23 -0
- ScreenMagnifier/hotkeys/mainwindow.py +56 -0
- ScreenMagnifier/imagefilters/__init__.py +24 -0
- ScreenMagnifier/imagefilters/core.py +172 -0
- ScreenMagnifier/imagefilters/imagefilters.py +220 -0
- ScreenMagnifier/imagefilters/main.py +23 -0
- ScreenMagnifier/imagefilters/mainwindow.py +120 -0
- ScreenMagnifier/magnifierview/__init__.py +16 -0
- ScreenMagnifier/magnifierview/magnifierview.py +1249 -0
- ScreenMagnifier/magnifierview/main.py +23 -0
- ScreenMagnifier/magnifierview/mainwindow.py +91 -0
- ScreenMagnifier/main.py +157 -0
- ScreenMagnifier/mainwindow.py +1368 -0
- ScreenMagnifier/mousecatcher/__init__.py +16 -0
- ScreenMagnifier/mousecatcher/main.py +23 -0
- ScreenMagnifier/mousecatcher/mainwindow.py +78 -0
- ScreenMagnifier/mousecatcher/mousecatcher.py +251 -0
- ScreenMagnifier/mousemove.py +259 -0
- ScreenMagnifier/netprotocol/__init__.py +25 -0
- ScreenMagnifier/netprotocol/main.py +23 -0
- ScreenMagnifier/netprotocol/mainwindow.py +91 -0
- ScreenMagnifier/netprotocol/netprotocol.py +372 -0
- ScreenMagnifier/netprotocol/wire.py +189 -0
- ScreenMagnifier/regionselector/__init__.py +16 -0
- ScreenMagnifier/regionselector/main.py +23 -0
- ScreenMagnifier/regionselector/mainwindow.py +70 -0
- ScreenMagnifier/regionselector/regionselector.py +549 -0
- ScreenMagnifier/remoteclient.py +636 -0
- ScreenMagnifier/resources/icon-128.png +0 -0
- ScreenMagnifier/resources/icon-16.png +0 -0
- ScreenMagnifier/resources/icon-24.png +0 -0
- ScreenMagnifier/resources/icon-256.png +0 -0
- ScreenMagnifier/resources/icon-32.png +0 -0
- ScreenMagnifier/resources/icon-48.png +0 -0
- ScreenMagnifier/resources/icon-512.png +0 -0
- ScreenMagnifier/resources/icon-64.png +0 -0
- ScreenMagnifier/resources/icon.icns +0 -0
- ScreenMagnifier/resources/icon.ico +0 -0
- ScreenMagnifier/screengrabber/__init__.py +16 -0
- ScreenMagnifier/screengrabber/main.py +23 -0
- ScreenMagnifier/screengrabber/mainwindow.py +79 -0
- ScreenMagnifier/screengrabber/screengrabber.py +558 -0
- ScreenMagnifier/server.py +150 -0
- ScreenMagnifier/serverpanel.py +379 -0
- ScreenMagnifier/shortcuteditor/__init__.py +16 -0
- ScreenMagnifier/shortcuteditor/main.py +23 -0
- ScreenMagnifier/shortcuteditor/mainwindow.py +54 -0
- ScreenMagnifier/shortcuteditor/shortcuteditor.py +411 -0
- ScreenMagnifier/shortcuts.py +118 -0
- ScreenMagnifier/shortcutspanel.py +140 -0
- ScreenMagnifier/support.py +127 -0
- ScreenMagnifier/translations/ar.json +387 -0
- ScreenMagnifier/translations/de.json +387 -0
- ScreenMagnifier/translations/es.json +387 -0
- ScreenMagnifier/translations/fr.json +387 -0
- ScreenMagnifier/translations/it.json +387 -0
- ScreenMagnifier/translations/ja.json +387 -0
- ScreenMagnifier/translations/ko.json +387 -0
- ScreenMagnifier/translations/pt_BR.json +387 -0
- ScreenMagnifier/translations/ru.json +387 -0
- ScreenMagnifier/translations/tr.json +387 -0
- ScreenMagnifier/translations/zh_CN.json +387 -0
- ScreenMagnifier/translator/__init__.py +16 -0
- ScreenMagnifier/translator/main.py +23 -0
- ScreenMagnifier/translator/mainwindow.py +62 -0
- ScreenMagnifier/translator/translator.py +284 -0
- ScreenMagnifier/upscaler/__init__.py +24 -0
- ScreenMagnifier/upscaler/core.py +315 -0
- ScreenMagnifier/upscaler/main.py +23 -0
- ScreenMagnifier/upscaler/mainwindow.py +128 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x2.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x3.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN-small_x4.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x2.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x3.pb +0 -0
- ScreenMagnifier/upscaler/models/FSRCNN_x4.pb +0 -0
- ScreenMagnifier/upscaler/models/LICENSE-FSRCNN +201 -0
- ScreenMagnifier/upscaler/models/__init__.py +4 -0
- ScreenMagnifier/upscaler/upscaler.py +285 -0
- ScreenMagnifier/wincheck.py +65 -0
- ScreenMagnifier/zoomoverlay/__init__.py +16 -0
- ScreenMagnifier/zoomoverlay/main.py +23 -0
- ScreenMagnifier/zoomoverlay/mainwindow.py +99 -0
- ScreenMagnifier/zoomoverlay/zoomoverlay.py +1779 -0
- screenmagnifier-1.11.0.post8.dist-info/METADATA +591 -0
- screenmagnifier-1.11.0.post8.dist-info/RECORD +117 -0
- screenmagnifier-1.11.0.post8.dist-info/WHEEL +5 -0
- screenmagnifier-1.11.0.post8.dist-info/entry_points.txt +5 -0
- screenmagnifier-1.11.0.post8.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
mousecatcher package.
|
|
4
|
+
"""
|
|
5
|
+
from os.path import dirname
|
|
6
|
+
from sys import path
|
|
7
|
+
|
|
8
|
+
if not __package__ and dirname(__file__) not in path:
|
|
9
|
+
path.append(dirname(__file__))
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from .mousecatcher import GlobalMouseCatcher
|
|
13
|
+
except:
|
|
14
|
+
from mousecatcher import GlobalMouseCatcher
|
|
15
|
+
|
|
16
|
+
__all__ = ['GlobalMouseCatcher'] # type: list[str]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Entry point for the GlobalMouseCatcher demo.
|
|
4
|
+
"""
|
|
5
|
+
from os.path import dirname
|
|
6
|
+
from sys import path
|
|
7
|
+
|
|
8
|
+
if not __package__ and dirname(__file__) not in path:
|
|
9
|
+
path.append(dirname(__file__))
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from .mainwindow import MainWindow
|
|
13
|
+
except:
|
|
14
|
+
from mainwindow import MainWindow
|
|
15
|
+
|
|
16
|
+
if __name__ == '__main__':
|
|
17
|
+
from ManyQt.QtWidgets import QApplication
|
|
18
|
+
from sys import argv, exit
|
|
19
|
+
|
|
20
|
+
a = QApplication(argv) # type: QApplication
|
|
21
|
+
w = MainWindow() # type: MainWindow
|
|
22
|
+
w.show()
|
|
23
|
+
exit(a.exec_())
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Demo window for GlobalMouseCatcher: click anywhere on the screen, the clicks are reported and swallowed.
|
|
4
|
+
"""
|
|
5
|
+
from ManyQt.QtWidgets import QMainWindow, QVBoxLayout, QWidget, QPushButton, QListWidget, QLabel
|
|
6
|
+
from ManyQt.QtCore import QPoint, pyqtSlot
|
|
7
|
+
from os.path import dirname
|
|
8
|
+
from sys import path
|
|
9
|
+
|
|
10
|
+
if not __package__ and dirname(__file__) not in path:
|
|
11
|
+
path.append(dirname(__file__))
|
|
12
|
+
|
|
13
|
+
try:
|
|
14
|
+
from .mousecatcher import GlobalMouseCatcher
|
|
15
|
+
except:
|
|
16
|
+
from mousecatcher import GlobalMouseCatcher
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class MainWindow(QMainWindow):
|
|
20
|
+
"""
|
|
21
|
+
MainWindow class.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, *args, **kwargs):
|
|
25
|
+
"""
|
|
26
|
+
:param args: any
|
|
27
|
+
:param kwargs: any
|
|
28
|
+
"""
|
|
29
|
+
super(MainWindow, self).__init__(*args, **kwargs)
|
|
30
|
+
self.setWindowTitle(self.tr(u'GlobalMouseCatcher demo'))
|
|
31
|
+
self.resize(460, 340)
|
|
32
|
+
self.__m_catcher = GlobalMouseCatcher(clicked=self.onClicked, wheelTurned=lambda d: self.log('wheel {}'.format(d)),
|
|
33
|
+
keyPressed=self.onKey) # type: GlobalMouseCatcher
|
|
34
|
+
button = QPushButton(self.tr(u'Start catching (right-click or Esc stops)')) # type: QPushButton
|
|
35
|
+
button.clicked.connect(self.start)
|
|
36
|
+
self.__m_log = QListWidget() # type: QListWidget
|
|
37
|
+
wdg = QWidget() # type: QWidget
|
|
38
|
+
layout = QVBoxLayout(wdg) # type: QVBoxLayout
|
|
39
|
+
layout.addWidget(button)
|
|
40
|
+
layout.addWidget(QLabel(self.tr(u'Backend: {}').format(self.__m_catcher.getBackendName())))
|
|
41
|
+
layout.addWidget(self.__m_log)
|
|
42
|
+
self.setCentralWidget(wdg)
|
|
43
|
+
|
|
44
|
+
def log(self, text):
|
|
45
|
+
"""
|
|
46
|
+
:param text: str | unicode | QString
|
|
47
|
+
:return:
|
|
48
|
+
"""
|
|
49
|
+
self.__m_log.insertItem(0, u'{}'.format(text))
|
|
50
|
+
|
|
51
|
+
@pyqtSlot()
|
|
52
|
+
def start(self):
|
|
53
|
+
"""
|
|
54
|
+
:return:
|
|
55
|
+
"""
|
|
56
|
+
if not self.__m_catcher.start():
|
|
57
|
+
self.log(self.__m_catcher.getError())
|
|
58
|
+
|
|
59
|
+
@pyqtSlot(QPoint, int)
|
|
60
|
+
def onClicked(self, pos, button):
|
|
61
|
+
"""
|
|
62
|
+
:param pos: QPoint
|
|
63
|
+
:param button: int
|
|
64
|
+
:return:
|
|
65
|
+
"""
|
|
66
|
+
self.log('button {} at ({}, {})'.format(button, pos.x(), pos.y()))
|
|
67
|
+
if button == 2:
|
|
68
|
+
self.__m_catcher.stop()
|
|
69
|
+
|
|
70
|
+
@pyqtSlot(int)
|
|
71
|
+
def onKey(self, key):
|
|
72
|
+
"""
|
|
73
|
+
:param key: int
|
|
74
|
+
:return:
|
|
75
|
+
"""
|
|
76
|
+
self.log('key {}'.format(key))
|
|
77
|
+
if key == 0x01000000: # Qt.Key_Escape
|
|
78
|
+
self.__m_catcher.stop()
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
GlobalMouseCatcher: catches mouse clicks ANYWHERE on the screen (over any application or game) and swallows them,
|
|
4
|
+
while the cursor keeps moving normally - e.g. for a screen color picker.
|
|
5
|
+
Backends:
|
|
6
|
+
- qtgrab : Qt pointer + keyboard grab on a 1 px window (Linux / X11). Also reports keys (Esc, arrows).
|
|
7
|
+
- pynput : system mouse hook (Windows low-level hook, macOS Quartz event tap - needs the Accessibility
|
|
8
|
+
permission). Only button / wheel events are suppressed, movements pass through.
|
|
9
|
+
- auto : pynput on Windows / macOS, qtgrab elsewhere.
|
|
10
|
+
Signals: clicked(QPoint global position, int button 1 left / 2 right / 3 middle), wheelTurned(int delta, 120 per
|
|
11
|
+
notch), keyPressed(int Qt key, qtgrab only).
|
|
12
|
+
"""
|
|
13
|
+
from ManyQt.QtCore import Qt, QPoint, QObject, QThread, pyqtSignal, pyqtSlot, pyqtProperty
|
|
14
|
+
from ManyQt.QtWidgets import QWidget, QApplication
|
|
15
|
+
from ManyQt.QtGui import QCursor
|
|
16
|
+
from sys import platform
|
|
17
|
+
|
|
18
|
+
WM_BUTTONS = {0x0201: 1, 0x0204: 2, 0x0207: 3} # type: dict # Windows WM_*BUTTONDOWN -> button
|
|
19
|
+
WM_BUTTONS_UP = (0x0202, 0x0205, 0x0208) # type: tuple
|
|
20
|
+
WM_MOUSEWHEEL = 0x020A # type: int
|
|
21
|
+
CG_BUTTONS = {1: 1, 3: 2, 25: 3} # type: dict # macOS kCGEvent*MouseDown -> button
|
|
22
|
+
CG_BUTTONS_UP = (2, 4, 26) # type: tuple
|
|
23
|
+
CG_SCROLL = 22 # type: int
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _GrabWindow(QWidget):
|
|
27
|
+
"""
|
|
28
|
+
_GrabWindow class: 1 px window owning the pointer / keyboard grab.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, catcher):
|
|
32
|
+
"""
|
|
33
|
+
:param catcher: GlobalMouseCatcher
|
|
34
|
+
"""
|
|
35
|
+
super(_GrabWindow, self).__init__()
|
|
36
|
+
self.__m_catcher = catcher # type: GlobalMouseCatcher
|
|
37
|
+
flags = Qt.FramelessWindowHint | Qt.Tool | Qt.WindowStaysOnTopHint # type: int
|
|
38
|
+
if platform.startswith('linux'):
|
|
39
|
+
flags |= Qt.X11BypassWindowManagerHint
|
|
40
|
+
self.setWindowFlags(flags)
|
|
41
|
+
self.setGeometry(0, 0, 1, 1)
|
|
42
|
+
|
|
43
|
+
def mousePressEvent(self, e):
|
|
44
|
+
"""
|
|
45
|
+
:param e: QMouseEvent
|
|
46
|
+
:return:
|
|
47
|
+
"""
|
|
48
|
+
button = {Qt.LeftButton: 1, Qt.RightButton: 2, Qt.MiddleButton: 3}.get(e.button(), 0) # type: int
|
|
49
|
+
pos = e.globalPosition().toPoint() if hasattr(e, 'globalPosition') else e.globalPos() # type: QPoint
|
|
50
|
+
if button:
|
|
51
|
+
self.__m_catcher.clicked.emit(pos, button)
|
|
52
|
+
|
|
53
|
+
def wheelEvent(self, e):
|
|
54
|
+
"""
|
|
55
|
+
:param e: QWheelEvent
|
|
56
|
+
:return:
|
|
57
|
+
"""
|
|
58
|
+
self.__m_catcher.wheelTurned.emit(int(e.angleDelta().y()))
|
|
59
|
+
|
|
60
|
+
def keyPressEvent(self, e):
|
|
61
|
+
"""
|
|
62
|
+
:param e: QKeyEvent
|
|
63
|
+
:return:
|
|
64
|
+
"""
|
|
65
|
+
self.__m_catcher.keyPressed.emit(int(e.key()))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class GlobalMouseCatcher(QObject):
|
|
69
|
+
"""
|
|
70
|
+
GlobalMouseCatcher class.
|
|
71
|
+
"""
|
|
72
|
+
clicked = pyqtSignal(QPoint, int) # type: pyqtSignal
|
|
73
|
+
wheelTurned = pyqtSignal(int) # type: pyqtSignal
|
|
74
|
+
keyPressed = pyqtSignal(int) # type: pyqtSignal
|
|
75
|
+
activeChanged = pyqtSignal(bool) # type: pyqtSignal
|
|
76
|
+
_hookButton = pyqtSignal(int) # type: pyqtSignal # hook thread -> GUI thread
|
|
77
|
+
_hookWheel = pyqtSignal(int) # type: pyqtSignal
|
|
78
|
+
|
|
79
|
+
def __init__(self, *args, **kwargs):
|
|
80
|
+
"""
|
|
81
|
+
:param backend: (str | unicode | QString) 'auto', 'qtgrab' or 'pynput'.
|
|
82
|
+
:param cursorShape: (Qt.CursorShape) Cursor while catching (qtgrab).
|
|
83
|
+
:param clicked: callable | None
|
|
84
|
+
:param wheelTurned: callable | None
|
|
85
|
+
:param keyPressed: callable | None
|
|
86
|
+
:param args: any
|
|
87
|
+
:param kwargs: any
|
|
88
|
+
"""
|
|
89
|
+
backend = kwargs.pop('backend', 'auto') # type: str
|
|
90
|
+
cursorShape = kwargs.pop('cursorShape', Qt.CrossCursor) # type: int
|
|
91
|
+
clicked = kwargs.pop('clicked', None) # type: callable | None
|
|
92
|
+
wheelTurned = kwargs.pop('wheelTurned', None) # type: callable | None
|
|
93
|
+
keyPressed = kwargs.pop('keyPressed', None) # type: callable | None
|
|
94
|
+
super(GlobalMouseCatcher, self).__init__(*args, **kwargs)
|
|
95
|
+
for signal, slot in ((self.clicked, clicked), (self.wheelTurned, wheelTurned), (self.keyPressed, keyPressed)):
|
|
96
|
+
if callable(slot):
|
|
97
|
+
signal.connect(slot)
|
|
98
|
+
self.__m_backend = u'{}'.format(backend) if u'{}'.format(backend) in ('auto', 'qtgrab', 'pynput') else 'auto' # type: str
|
|
99
|
+
self.__m_cursorShape = cursorShape # type: int
|
|
100
|
+
self.__m_active = False # type: bool
|
|
101
|
+
self.__m_error = '' # type: str
|
|
102
|
+
self.__m_window = None # type: _GrabWindow | None
|
|
103
|
+
self.__m_listener = None
|
|
104
|
+
self._hookButton.connect(lambda b: self.clicked.emit(QCursor.pos(), b), Qt.QueuedConnection)
|
|
105
|
+
self._hookWheel.connect(self.wheelTurned.emit, Qt.QueuedConnection)
|
|
106
|
+
|
|
107
|
+
# ---------- Helpers ----------
|
|
108
|
+
def getBackendName(self):
|
|
109
|
+
"""
|
|
110
|
+
:return: (str | unicode | QString) Backend used by start(): 'qtgrab' or 'pynput'.
|
|
111
|
+
"""
|
|
112
|
+
if self.__m_backend != 'auto':
|
|
113
|
+
return self.__m_backend
|
|
114
|
+
return 'pynput' if platform in ('win32', 'darwin') else 'qtgrab'
|
|
115
|
+
|
|
116
|
+
def winFilter(self, msg, data):
|
|
117
|
+
"""
|
|
118
|
+
Windows low-level hook filter (pynput win32_event_filter): report and swallow buttons / wheel.
|
|
119
|
+
:param msg: (int) WM_* message.
|
|
120
|
+
:param data: MSLLHOOKSTRUCT
|
|
121
|
+
:return: bool
|
|
122
|
+
"""
|
|
123
|
+
if msg in WM_BUTTONS:
|
|
124
|
+
self._hookButton.emit(WM_BUTTONS[msg])
|
|
125
|
+
elif msg == WM_MOUSEWHEEL:
|
|
126
|
+
delta = (int(data.mouseData) >> 16) & 0xFFFF # type: int
|
|
127
|
+
self._hookWheel.emit(delta - 0x10000 if delta >= 0x8000 else delta)
|
|
128
|
+
elif msg not in WM_BUTTONS_UP:
|
|
129
|
+
return True # Movements pass through untouched.
|
|
130
|
+
if self.__m_listener is not None:
|
|
131
|
+
self.__m_listener.suppress_event() # Raises inside pynput: the event never reaches other apps.
|
|
132
|
+
return False
|
|
133
|
+
|
|
134
|
+
def macIntercept(self, eventType, event):
|
|
135
|
+
"""
|
|
136
|
+
macOS event tap (pynput darwin_intercept): report and swallow buttons / wheel.
|
|
137
|
+
:param eventType: (int) kCGEvent* type.
|
|
138
|
+
:param event: CGEventRef
|
|
139
|
+
:return: (CGEventRef | None) None swallows the event.
|
|
140
|
+
"""
|
|
141
|
+
if eventType in CG_BUTTONS:
|
|
142
|
+
self._hookButton.emit(CG_BUTTONS[eventType])
|
|
143
|
+
return None
|
|
144
|
+
if eventType in CG_BUTTONS_UP:
|
|
145
|
+
return None
|
|
146
|
+
if eventType == CG_SCROLL:
|
|
147
|
+
try:
|
|
148
|
+
from Quartz import CGEventGetIntegerValueField, kCGScrollWheelEventDeltaAxis1
|
|
149
|
+
self._hookWheel.emit(int(CGEventGetIntegerValueField(event, kCGScrollWheelEventDeltaAxis1)) * 120)
|
|
150
|
+
except:
|
|
151
|
+
pass
|
|
152
|
+
return None
|
|
153
|
+
return event
|
|
154
|
+
|
|
155
|
+
def _grab(self):
|
|
156
|
+
"""
|
|
157
|
+
X11 maps a new window asynchronously and refuses to grab for a window that is not viewable yet: retry until
|
|
158
|
+
the window system confirms both grabs (up to ~1 s).
|
|
159
|
+
:return: (bool) Pointer and keyboard grabbed.
|
|
160
|
+
"""
|
|
161
|
+
for _ in range(40):
|
|
162
|
+
QApplication.processEvents()
|
|
163
|
+
handle = self.__m_window.windowHandle()
|
|
164
|
+
if handle is not None and self.__m_window.isVisible():
|
|
165
|
+
if handle.setMouseGrabEnabled(True) and handle.setKeyboardGrabEnabled(True):
|
|
166
|
+
return True
|
|
167
|
+
QThread.msleep(25)
|
|
168
|
+
return False
|
|
169
|
+
|
|
170
|
+
# ---------- Public API ----------
|
|
171
|
+
@pyqtSlot()
|
|
172
|
+
def start(self):
|
|
173
|
+
"""
|
|
174
|
+
:return: (bool) Catching.
|
|
175
|
+
"""
|
|
176
|
+
if self.__m_active:
|
|
177
|
+
return True
|
|
178
|
+
self.__m_error = u'' # type: str
|
|
179
|
+
try:
|
|
180
|
+
if self.getBackendName() == 'pynput':
|
|
181
|
+
from pynput import mouse
|
|
182
|
+
self.__m_listener = mouse.Listener(
|
|
183
|
+
win32_event_filter=self.winFilter, darwin_intercept=self.macIntercept)
|
|
184
|
+
self.__m_listener.daemon = True
|
|
185
|
+
self.__m_listener.start()
|
|
186
|
+
else:
|
|
187
|
+
self.__m_window = _GrabWindow(self) # type: _GrabWindow
|
|
188
|
+
self.__m_window.show()
|
|
189
|
+
if not self._grab():
|
|
190
|
+
raise RuntimeError(u'The pointer grab was refused (another application holds it)')
|
|
191
|
+
self.__m_window.grabMouse(QCursor(self.__m_cursorShape)) # Qt-side routing of the grabbed events.
|
|
192
|
+
self.__m_window.grabKeyboard()
|
|
193
|
+
except Exception as e:
|
|
194
|
+
self.__m_error = u'Global mouse capture unavailable: {}'.format(e) # type: str
|
|
195
|
+
self.stop()
|
|
196
|
+
return False
|
|
197
|
+
self.__m_active = True # type: bool
|
|
198
|
+
self.activeChanged.emit(True)
|
|
199
|
+
return True
|
|
200
|
+
|
|
201
|
+
@pyqtSlot()
|
|
202
|
+
def stop(self):
|
|
203
|
+
"""
|
|
204
|
+
:return:
|
|
205
|
+
"""
|
|
206
|
+
if self.__m_listener is not None:
|
|
207
|
+
try:
|
|
208
|
+
self.__m_listener.stop()
|
|
209
|
+
except:
|
|
210
|
+
pass
|
|
211
|
+
self.__m_listener = None
|
|
212
|
+
if self.__m_window is not None:
|
|
213
|
+
self.__m_window.releaseKeyboard()
|
|
214
|
+
self.__m_window.releaseMouse()
|
|
215
|
+
self.__m_window.close()
|
|
216
|
+
self.__m_window.deleteLater()
|
|
217
|
+
self.__m_window = None
|
|
218
|
+
if self.__m_active:
|
|
219
|
+
self.__m_active = False # type: bool
|
|
220
|
+
self.activeChanged.emit(False)
|
|
221
|
+
|
|
222
|
+
def isActive(self):
|
|
223
|
+
"""
|
|
224
|
+
:return: bool
|
|
225
|
+
"""
|
|
226
|
+
return self.__m_active
|
|
227
|
+
|
|
228
|
+
def getError(self):
|
|
229
|
+
"""
|
|
230
|
+
:return: str | unicode | QString
|
|
231
|
+
"""
|
|
232
|
+
return self.__m_error
|
|
233
|
+
|
|
234
|
+
def getBackend(self):
|
|
235
|
+
"""
|
|
236
|
+
:return: str | unicode | QString
|
|
237
|
+
"""
|
|
238
|
+
return self.__m_backend
|
|
239
|
+
|
|
240
|
+
@pyqtSlot('QString')
|
|
241
|
+
@pyqtSlot(str)
|
|
242
|
+
def setBackend(self, backend):
|
|
243
|
+
"""
|
|
244
|
+
:param backend: (str | unicode | QString) 'auto', 'qtgrab' or 'pynput' (used at the next start()).
|
|
245
|
+
:return:
|
|
246
|
+
"""
|
|
247
|
+
self.__m_backend = u'{}'.format(backend) if u'{}'.format(backend) in ('auto', 'qtgrab', 'pynput') else 'auto' # type: str
|
|
248
|
+
|
|
249
|
+
# ---------- Properties ----------
|
|
250
|
+
backend = pyqtProperty('QString', fget=getBackend, fset=setBackend) # type: pyqtProperty
|
|
251
|
+
active = pyqtProperty(bool, fget=isActive, notify=activeChanged) # type: pyqtProperty
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Mouse movements like a real mouse, for games that capture the mouse (first-person and 3D games hide the pointer and
|
|
4
|
+
turn the view with the raw mouse movements, so moving the pointer's position has no effect there):
|
|
5
|
+
sendRelativeMove(dx, dy) -> bool Windows: SendInput (raw input sees it); Linux X11: XTest relative motion;
|
|
6
|
+
macOS: Quartz mouse-moved event with deltas; Wayland: not possible (False).
|
|
7
|
+
ButtonWatcher Is the right mouse button held? (pynput listener, nothing is swallowed)
|
|
8
|
+
mouseCapture() -> str 'clipped' (Windows: the pointer is confined - a game), 'hidden' (the cursor
|
|
9
|
+
is invisible: a game, or a video player resting) or '' (a normal pointer)
|
|
10
|
+
"""
|
|
11
|
+
from sys import platform
|
|
12
|
+
from os import environ
|
|
13
|
+
import ctypes
|
|
14
|
+
|
|
15
|
+
_X11 = [] # type: list # [display] opened on first use
|
|
16
|
+
_QUARTZ = [] # type: list # [library]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _isWayland():
|
|
20
|
+
"""
|
|
21
|
+
:return: (bool) A Wayland session (applications may not move the mouse there).
|
|
22
|
+
"""
|
|
23
|
+
return platform.startswith('linux') and (environ.get('WAYLAND_DISPLAY') and not environ.get('DISPLAY') or
|
|
24
|
+
environ.get('QT_QPA_PLATFORM', '').startswith('wayland'))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def canSendRelative():
|
|
28
|
+
"""
|
|
29
|
+
:return: (bool) This system lets the application send relative mouse movements.
|
|
30
|
+
"""
|
|
31
|
+
if platform == 'win32':
|
|
32
|
+
return True
|
|
33
|
+
if platform == 'darwin':
|
|
34
|
+
return _quartz() is not None
|
|
35
|
+
return not _isWayland() and _x11() is not None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _x11():
|
|
39
|
+
"""
|
|
40
|
+
:return: Xlib display | None
|
|
41
|
+
"""
|
|
42
|
+
if not _X11:
|
|
43
|
+
try:
|
|
44
|
+
from Xlib import display as xdisplay
|
|
45
|
+
from Xlib.ext import xtest # noqa: F401 (the extension must exist)
|
|
46
|
+
d = xdisplay.Display()
|
|
47
|
+
_X11.append(d if d.has_extension('XTEST') else None)
|
|
48
|
+
except Exception:
|
|
49
|
+
_X11.append(None)
|
|
50
|
+
return _X11[0]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _quartz():
|
|
54
|
+
"""
|
|
55
|
+
:return: ctypes library | None
|
|
56
|
+
"""
|
|
57
|
+
if not _QUARTZ:
|
|
58
|
+
try:
|
|
59
|
+
lib = ctypes.cdll.LoadLibrary(
|
|
60
|
+
'/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices')
|
|
61
|
+
_QUARTZ.append(lib)
|
|
62
|
+
except Exception:
|
|
63
|
+
_QUARTZ.append(None)
|
|
64
|
+
return _QUARTZ[0]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class _MouseInput(ctypes.Structure):
|
|
68
|
+
"""
|
|
69
|
+
_MouseInput class: Windows MOUSEINPUT.
|
|
70
|
+
"""
|
|
71
|
+
_fields_ = [('dx', ctypes.c_long), ('dy', ctypes.c_long), ('mouseData', ctypes.c_ulong),
|
|
72
|
+
('dwFlags', ctypes.c_ulong), ('time', ctypes.c_ulong), ('dwExtraInfo', ctypes.c_void_p)]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class _Input(ctypes.Structure):
|
|
76
|
+
"""
|
|
77
|
+
_Input class: Windows INPUT (type + the mouse / keyboard / hardware union).
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
class _U(ctypes.Union):
|
|
81
|
+
"""
|
|
82
|
+
_U class: the INPUT union (padded to its largest member).
|
|
83
|
+
"""
|
|
84
|
+
_fields_ = [('mi', _MouseInput), ('pad', ctypes.c_byte * 32)]
|
|
85
|
+
|
|
86
|
+
_anonymous_ = ('u',)
|
|
87
|
+
_fields_ = [('type', ctypes.c_ulong), ('u', _U)]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class _Rect(ctypes.Structure):
|
|
91
|
+
"""
|
|
92
|
+
_Rect class: Windows RECT.
|
|
93
|
+
"""
|
|
94
|
+
_fields_ = [('left', ctypes.c_long), ('top', ctypes.c_long), ('right', ctypes.c_long), ('bottom', ctypes.c_long)]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class _CursorInfo(ctypes.Structure):
|
|
98
|
+
"""
|
|
99
|
+
_CursorInfo class: Windows CURSORINFO.
|
|
100
|
+
"""
|
|
101
|
+
_fields_ = [('cbSize', ctypes.c_ulong), ('flags', ctypes.c_ulong), ('hCursor', ctypes.c_void_p),
|
|
102
|
+
('x', ctypes.c_long), ('y', ctypes.c_long)]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def mouseCapture():
|
|
106
|
+
"""
|
|
107
|
+
How the mouse pointer is held right now (asked to the system).
|
|
108
|
+
:return: (str | unicode | QString)
|
|
109
|
+
'clipped' (Windows: confined to a rect - games do that), 'hidden' (invisible cursor: a game, or
|
|
110
|
+
a video player resting - tell them apart by moving it), '' (a normal, visible pointer) or '' when unknown.
|
|
111
|
+
"""
|
|
112
|
+
try:
|
|
113
|
+
if platform == 'win32':
|
|
114
|
+
user32 = ctypes.windll.user32
|
|
115
|
+
clip = _Rect()
|
|
116
|
+
if user32.GetClipCursor(ctypes.byref(clip)):
|
|
117
|
+
width = user32.GetSystemMetrics(78) # SM_CXVIRTUALSCREEN
|
|
118
|
+
height = user32.GetSystemMetrics(79) # SM_CYVIRTUALSCREEN
|
|
119
|
+
if clip.right - clip.left < width or clip.bottom - clip.top < height:
|
|
120
|
+
return 'clipped'
|
|
121
|
+
info = _CursorInfo()
|
|
122
|
+
info.cbSize = ctypes.sizeof(_CursorInfo)
|
|
123
|
+
if user32.GetCursorInfo(ctypes.byref(info)) and not (info.flags & 1): # CURSOR_SHOWING
|
|
124
|
+
return 'hidden'
|
|
125
|
+
return ''
|
|
126
|
+
if platform == 'darwin':
|
|
127
|
+
q = _quartz()
|
|
128
|
+
if q is not None:
|
|
129
|
+
q.CGCursorIsVisible.restype = ctypes.c_bool
|
|
130
|
+
return '' if q.CGCursorIsVisible() else 'hidden'
|
|
131
|
+
return ''
|
|
132
|
+
d = _x11()
|
|
133
|
+
if d is None or _isWayland():
|
|
134
|
+
return ''
|
|
135
|
+
if not getattr(d, '_sm_xfixes', False):
|
|
136
|
+
d.xfixes_query_version()
|
|
137
|
+
d._sm_xfixes = True
|
|
138
|
+
image = d.xfixes_get_cursor_image(d.screen().root)
|
|
139
|
+
pixels = list(image.cursor_image) # ARGB
|
|
140
|
+
return 'hidden' if pixels and not any((p >> 24) & 0xFF for p in pixels) else ''
|
|
141
|
+
except Exception:
|
|
142
|
+
return ''
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class _CGPoint(ctypes.Structure):
|
|
146
|
+
"""
|
|
147
|
+
_CGPoint class: macOS CGPoint.
|
|
148
|
+
"""
|
|
149
|
+
_fields_ = [('x', ctypes.c_double), ('y', ctypes.c_double)]
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def sendRelativeMove(dx, dy):
|
|
153
|
+
"""
|
|
154
|
+
Move the mouse by (dx, dy) counts, as a physical mouse would.
|
|
155
|
+
:param dx: int
|
|
156
|
+
:param dy: int
|
|
157
|
+
:return: (bool) Sent.
|
|
158
|
+
"""
|
|
159
|
+
dx, dy = int(dx), int(dy)
|
|
160
|
+
if not dx and not dy:
|
|
161
|
+
return True
|
|
162
|
+
try:
|
|
163
|
+
if platform == 'win32':
|
|
164
|
+
event = _Input(type=0) # INPUT_MOUSE
|
|
165
|
+
event.mi = _MouseInput(dx, dy, 0, 0x0001, 0, None) # MOUSEEVENTF_MOVE (relative)
|
|
166
|
+
return ctypes.windll.user32.SendInput(1, ctypes.byref(event), ctypes.sizeof(_Input)) == 1
|
|
167
|
+
if platform == 'darwin':
|
|
168
|
+
q = _quartz()
|
|
169
|
+
if q is None:
|
|
170
|
+
return False
|
|
171
|
+
q.CGEventCreate.restype = ctypes.c_void_p
|
|
172
|
+
q.CGEventGetLocation.restype = _CGPoint
|
|
173
|
+
q.CGEventGetLocation.argtypes = [ctypes.c_void_p]
|
|
174
|
+
q.CGEventCreateMouseEvent.restype = ctypes.c_void_p
|
|
175
|
+
q.CGEventCreateMouseEvent.argtypes = [ctypes.c_void_p, ctypes.c_uint32, _CGPoint, ctypes.c_uint32]
|
|
176
|
+
q.CGEventSetIntegerValueField.argtypes = [ctypes.c_void_p, ctypes.c_uint32, ctypes.c_int64]
|
|
177
|
+
q.CGEventPost.argtypes = [ctypes.c_uint32, ctypes.c_void_p]
|
|
178
|
+
q.CFRelease.argtypes = [ctypes.c_void_p]
|
|
179
|
+
probe = q.CGEventCreate(None)
|
|
180
|
+
here = q.CGEventGetLocation(probe)
|
|
181
|
+
q.CFRelease(probe)
|
|
182
|
+
event = q.CGEventCreateMouseEvent(None, 5, _CGPoint(here.x + dx, here.y + dy), 0) # kCGEventMouseMoved
|
|
183
|
+
q.CGEventSetIntegerValueField(event, 4, dx) # kCGMouseEventDeltaX
|
|
184
|
+
q.CGEventSetIntegerValueField(event, 5, dy) # kCGMouseEventDeltaY
|
|
185
|
+
q.CGEventPost(0, event) # kCGHIDEventTap
|
|
186
|
+
q.CFRelease(event)
|
|
187
|
+
return True
|
|
188
|
+
d = _x11()
|
|
189
|
+
if d is None or _isWayland():
|
|
190
|
+
return False
|
|
191
|
+
from Xlib.ext import xtest
|
|
192
|
+
from Xlib import X
|
|
193
|
+
xtest.fake_input(d, X.MotionNotify, detail=1, x=dx, y=dy) # detail 1: relative motion
|
|
194
|
+
d.sync()
|
|
195
|
+
return True
|
|
196
|
+
except Exception:
|
|
197
|
+
return False
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class ButtonWatcher(object):
|
|
201
|
+
"""
|
|
202
|
+
ButtonWatcher class: tells whether the right mouse button is held (a pynput listener; clicks still reach the
|
|
203
|
+
game). Start it only while needed.
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
def __init__(self):
|
|
207
|
+
"""
|
|
208
|
+
"""
|
|
209
|
+
self.__m_listener = None
|
|
210
|
+
self.__m_held = False # type: bool
|
|
211
|
+
|
|
212
|
+
def start(self):
|
|
213
|
+
"""
|
|
214
|
+
:return: (bool) Watching.
|
|
215
|
+
"""
|
|
216
|
+
if self.__m_listener is not None:
|
|
217
|
+
return True
|
|
218
|
+
try:
|
|
219
|
+
from pynput import mouse
|
|
220
|
+
except Exception:
|
|
221
|
+
return False
|
|
222
|
+
|
|
223
|
+
def onClick(x, y, button, pressed):
|
|
224
|
+
"""
|
|
225
|
+
:param x: int
|
|
226
|
+
:param y: int
|
|
227
|
+
:param button: pynput.mouse.Button
|
|
228
|
+
:param pressed: bool
|
|
229
|
+
:return:
|
|
230
|
+
"""
|
|
231
|
+
if button == mouse.Button.right:
|
|
232
|
+
self.__m_held = bool(pressed)
|
|
233
|
+
|
|
234
|
+
try:
|
|
235
|
+
self.__m_listener = mouse.Listener(on_click=onClick)
|
|
236
|
+
self.__m_listener.daemon = True
|
|
237
|
+
self.__m_listener.start()
|
|
238
|
+
return True
|
|
239
|
+
except Exception:
|
|
240
|
+
self.__m_listener = None
|
|
241
|
+
return False
|
|
242
|
+
|
|
243
|
+
def stop(self):
|
|
244
|
+
"""
|
|
245
|
+
:return:
|
|
246
|
+
"""
|
|
247
|
+
if self.__m_listener is not None:
|
|
248
|
+
try:
|
|
249
|
+
self.__m_listener.stop()
|
|
250
|
+
except Exception:
|
|
251
|
+
pass
|
|
252
|
+
self.__m_listener = None
|
|
253
|
+
self.__m_held = False # type: bool
|
|
254
|
+
|
|
255
|
+
def isHeld(self):
|
|
256
|
+
"""
|
|
257
|
+
:return: (bool) The right mouse button is held.
|
|
258
|
+
"""
|
|
259
|
+
return self.__m_held
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
netprotocol package: the Qt-free part (wire.py) is always available - the headless server uses it, also where Qt is
|
|
4
|
+
not installed (e.g. Android); the Qt classes are available when a Qt binding is installed (None otherwise).
|
|
5
|
+
"""
|
|
6
|
+
from os.path import dirname
|
|
7
|
+
from sys import path
|
|
8
|
+
|
|
9
|
+
if not __package__ and dirname(__file__) not in path:
|
|
10
|
+
path.append(dirname(__file__))
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
from .wire import packMessage, MessageParser, DEFAULT_PORT, encodeArray, decodeArray, availableFormats
|
|
14
|
+
except:
|
|
15
|
+
from wire import packMessage, MessageParser, DEFAULT_PORT, encodeArray, decodeArray, availableFormats
|
|
16
|
+
try:
|
|
17
|
+
from .netprotocol import FrameChannel, FrameServer, encodeImage, decodeImage
|
|
18
|
+
except:
|
|
19
|
+
try:
|
|
20
|
+
from netprotocol import FrameChannel, FrameServer, encodeImage, decodeImage
|
|
21
|
+
except: # No Qt binding: the Qt-free part only.
|
|
22
|
+
FrameChannel = FrameServer = encodeImage = decodeImage = None
|
|
23
|
+
|
|
24
|
+
__all__ = ['packMessage', 'MessageParser', 'DEFAULT_PORT', 'encodeArray', 'decodeArray', 'availableFormats',
|
|
25
|
+
'FrameChannel', 'FrameServer', 'encodeImage', 'decodeImage'] # type: list[str]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding=utf-8
|
|
2
|
+
"""
|
|
3
|
+
Entry point for the FrameChannel demo.
|
|
4
|
+
"""
|
|
5
|
+
from os.path import dirname
|
|
6
|
+
from sys import path
|
|
7
|
+
|
|
8
|
+
if not __package__ and dirname(__file__) not in path:
|
|
9
|
+
path.append(dirname(__file__))
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from .mainwindow import MainWindow
|
|
13
|
+
except:
|
|
14
|
+
from mainwindow import MainWindow
|
|
15
|
+
|
|
16
|
+
if __name__ == '__main__':
|
|
17
|
+
from ManyQt.QtWidgets import QApplication
|
|
18
|
+
from sys import argv, exit
|
|
19
|
+
|
|
20
|
+
a = QApplication(argv) # type: QApplication
|
|
21
|
+
w = MainWindow() # type: MainWindow
|
|
22
|
+
w.show()
|
|
23
|
+
exit(a.exec_())
|