feat: detect Windows profile for install and input

This commit is contained in:
alex
2026-06-07 18:26:16 +02:00
parent d0ecf3afdc
commit 86e3cccbc9
10 changed files with 252 additions and 36 deletions
+16 -20
View File
@@ -5,26 +5,17 @@ No kernel drivers, no third-party DLLs. Only standard system DLLs (user32, kerne
import ctypes
import time
import struct
import platform
from ctypes import wintypes
from utils.misc import wait
from utils.os_detect import detect_os
# ─── Win10 vs Win11 mouse mode detection ───
# Win10 vs Win11 mouse mode detection
# Win10: SendInput needs MOUSEEVENTF_ABSOLUTE for correct positioning
# Win11 (25H2+): ABSOLUTE flag breaks mouse — use relative-only
# Detect at import time so the whole session uses the right mode.
def _is_win11():
"""Return True if running on Windows 11 (build >= 22000)."""
try:
ver = platform.win32_ver() # ('10', '10.0.26200', 'SP0', ...)
build_str = ver[1].split('.')[2] # '26200'
build = int(build_str)
return build >= 22000
except Exception:
return False
_USE_ABSOLUTE_MOUSE = not _is_win11() # True for Win10, False for Win11
_OS_INFO = detect_os()
_USE_ABSOLUTE_MOUSE = _OS_INFO.use_absolute_mouse
# ─── user32 constants ───
@@ -196,7 +187,7 @@ def _make_mouse_input(flags: int, dx: int = 0, dy: int = 0, data: int = 0):
i.union.mi.dx = dx
i.union.mi.dy = dy
i.union.mi.mouseData = data
i.union.mi.dwFlags = flags | (MOUSEEVENTF_ABSOLUTE if _USE_ABSOLUTE_MOUSE else 0)
i.union.mi.dwFlags = flags
i.union.mi.dwExtraInfo = None
return i
@@ -274,12 +265,17 @@ def get_screen_size():
return user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
def mouse_move(x: int, y: int):
"""Move mouse to absolute screen position (uses absolute SendInput)."""
screen_w, screen_h = get_screen_size()
# SendInput expects normalized absolute coordinates 0-65535
norm_x = int(x * 65535 / screen_w)
norm_y = int(y * 65535 / screen_h)
_send_input(_make_mouse_input(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, norm_x, norm_y))
"""Move mouse to an absolute screen position using the OS-specific mode."""
if _USE_ABSOLUTE_MOUSE:
screen_w, screen_h = get_screen_size()
# SendInput expects normalized absolute coordinates 0-65535.
norm_x = int(x * 65535 / screen_w)
norm_y = int(y * 65535 / screen_h)
_send_input(_make_mouse_input(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, norm_x, norm_y))
return
cur_x, cur_y = get_cursor_pos()
_send_input(_make_mouse_input(MOUSEEVENTF_MOVE, int(x - cur_x), int(y - cur_y)))
def mouse_down(button: str = "left"):
"""Press mouse button down."""