Capture the primary monitor and return PNG bytes in memory.
Returns None on failure.
Source code in core\gui\handler.py
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 | @classmethod
def get_screen_state(cls) -> Optional[bytes]:
"""
Capture the primary monitor and return PNG bytes in memory.
Returns None on failure.
"""
try:
with mss.mss() as sct:
monitors = sct.monitors
# Primary monitor is index 1 if available
monitor = monitors[1] if len(monitors) > 1 else monitors[0]
shot = sct.grab(monitor)
png_bytes = mss.tools.to_png(
shot.rgb,
shot.size,
output=None,
)
return png_bytes
except Exception as e:
print(f"[ScreenState ERROR] {e}")
return None
|