Import aus Monorepo (frischer Start)
This commit is contained in:
67
auto_recover.py
Normal file
67
auto_recover.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
AutoRecover - Drucker Fehler Handler
|
||||
Erkennt das "Error"-Fenster (Java AWT) und klickt automatisch "Recover" (max. 3x).
|
||||
"""
|
||||
|
||||
import win32gui
|
||||
import win32con
|
||||
import ctypes
|
||||
import time
|
||||
|
||||
MAX_VERSUCHE = 3
|
||||
PRUEF_INTERVAL = 2 # Sekunden zwischen den Checks
|
||||
|
||||
def click_recover_button(hwnd):
|
||||
"""
|
||||
Holt die Fensterposition und klickt auf den Recover-Button.
|
||||
Der Button ist zentriert am unteren Rand des Fensters.
|
||||
"""
|
||||
# Fenster in den Vordergrund holen
|
||||
win32gui.SetForegroundWindow(hwnd)
|
||||
time.sleep(0.3)
|
||||
|
||||
# Fensterposition und -größe ermitteln
|
||||
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
|
||||
width = right - left
|
||||
height = bottom - top
|
||||
|
||||
# Recover-Button liegt ca. bei: horizontal zentriert, ~85% der Höhe
|
||||
click_x = left + width // 2
|
||||
click_y = top + int(height * 0.85)
|
||||
|
||||
# Mausklick simulieren
|
||||
ctypes.windll.user32.SetCursorPos(click_x, click_y)
|
||||
time.sleep(0.1)
|
||||
ctypes.windll.user32.mouse_event(0x0002, 0, 0, 0, 0) # linke Taste runter
|
||||
ctypes.windll.user32.mouse_event(0x0004, 0, 0, 0, 0) # linke Taste hoch
|
||||
|
||||
print(f" → Klick auf Position ({click_x}, {click_y})")
|
||||
|
||||
def main():
|
||||
versuche = 0
|
||||
print("AutoRecover läuft... (Strg+C zum Beenden)")
|
||||
print(f"Maximal {MAX_VERSUCHE} Versuche.\n")
|
||||
|
||||
while versuche < MAX_VERSUCHE:
|
||||
hwnd = win32gui.FindWindow(None, "Error")
|
||||
|
||||
if hwnd and win32gui.IsWindowVisible(hwnd):
|
||||
versuche += 1
|
||||
print(f"[Versuch {versuche}/{MAX_VERSUCHE}] Fehlerfenster gefunden!")
|
||||
|
||||
time.sleep(0.5)
|
||||
click_recover_button(hwnd)
|
||||
|
||||
if versuche >= MAX_VERSUCHE:
|
||||
print(f"\nMaximale Versuche ({MAX_VERSUCHE}) erreicht. Programm beendet.")
|
||||
break
|
||||
|
||||
time.sleep(3)
|
||||
else:
|
||||
time.sleep(PRUEF_INTERVAL)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\nProgramm manuell beendet.")
|
||||
Reference in New Issue
Block a user