Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht, live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s, echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings angefasst, damit keine Einrueckung faellt.
71 lines
3.7 KiB
Python
71 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Messung: erreicht ein Klick an den Prozess (pid) den Tisch?
|
|
|
|
Drei Varianten, jede wartet auf einen eigenen Zug (deshalb 2-4 Minuten):
|
|
A Fenster aktiviert + globaler Klick - Kontrolle (so klickt der Laeufer heute)
|
|
B Hintergrund + pid-Klick, absolut - die "sandboxed Maus"
|
|
C Hintergrund + pid-Klick, fenster-relativ - falls die App so deutet
|
|
|
|
Beleg ist eine eigene Aktion im Log (game.user_action); gemessen wird auch, ob sich der Zeiger bewegt hat - bleibt er liegen, ist der Rechner unberuehrt.
|
|
|
|
(nohup python3 -u werkzeuge/messung_eingabe.py >| /tmp/messung.log 2>&1 & )
|
|
"""
|
|
import ctypes, os, re, subprocess, sys, time
|
|
sys.path.insert(0, "hand")
|
|
sys.path.insert(0, os.path.join(_w, "client"))
|
|
import fenster
|
|
from click import AS, CGPoint, MOVED, DOWN, UP
|
|
AS.CGEventCreate.restype = ctypes.c_void_p; AS.CGEventCreate.argtypes = [ctypes.c_void_p]
|
|
AS.CGEventGetLocation.restype = CGPoint; AS.CGEventGetLocation.argtypes = [ctypes.c_void_p]
|
|
AS.CGEventCreateMouseEvent.restype = ctypes.c_void_p
|
|
AS.CGEventCreateMouseEvent.argtypes = [ctypes.c_void_p, ctypes.c_uint32, CGPoint, ctypes.c_uint32]
|
|
AS.CGEventPost.argtypes = [ctypes.c_uint32, ctypes.c_void_p]
|
|
AS.CGEventPostToPid.argtypes = [ctypes.c_int, ctypes.c_void_p]
|
|
LOG = os.path.expanduser("~/Library/Logs/CoinPoker/main.log")
|
|
def sag(*a): print(*a, flush=True)
|
|
def log(): return open(LOG, errors="replace").read()
|
|
def zeiger():
|
|
z = AS.CGEventGetLocation(AS.CGEventCreate(None)); return (round(z.x), round(z.y))
|
|
def post(art, px, py, pid=None):
|
|
ev = AS.CGEventCreateMouseEvent(None, art, CGPoint(px, py), 0)
|
|
AS.CGEventPostToPid(pid, ev) if pid else AS.CGEventPost(0, ev); time.sleep(0.05)
|
|
def klick(px, py, pid=None, aktiv=False, f=None):
|
|
if aktiv and f:
|
|
subprocess.run(["osascript","-e",f'tell application "System Events" to set frontmost of (first process whose unix id is {f["pid"]}) to true'], capture_output=True)
|
|
time.sleep(1)
|
|
for a in (MOVED, DOWN, UP): post(a, px, py, pid)
|
|
def warte(stand, frist=110):
|
|
ende = time.time()+frist
|
|
while time.time() < ende:
|
|
neu = log()[stand:]
|
|
if "game.user_turn" in neu and "mmintel" in neu: return True
|
|
time.sleep(1)
|
|
return False
|
|
|
|
# Fenster notfalls wieder oeffnen (letzter Raum aus dem Log)
|
|
if not fenster.tischfenster():
|
|
r = list(dict.fromkeys(re.findall(r'"RoomName":"([^"]+)"', log()[-40000:])))[-1]
|
|
sag("kein Fenster -> join", r)
|
|
subprocess.run(["node","lobby/cdp.mjs","--eval",
|
|
f'(()=>{{const r=document.querySelector(`[data-table-id="{r}"]`);if(r){{r.querySelector("button").click();return "ok"}}return "Zeile fehlt"}})()'],
|
|
capture_output=True, text=True)
|
|
for _ in range(25):
|
|
time.sleep(1)
|
|
if fenster.tischfenster(): break
|
|
f = (fenster.tischfenster() or [None])[0]
|
|
if not f: raise SystemExit("kein Fenster")
|
|
x, y, w, h = f["rect"]
|
|
call = (round(x+w*0.796), round(y+h*0.943)); rel = (round(w*0.796), round(h*0.943))
|
|
sag("Fenster", f["pid"], f["rect"], "| Call absolut", call, "| relativ", rel, "| Zeiger", zeiger())
|
|
|
|
for name, cmd in (("A aktiviert+global (Kontrolle)", lambda: klick(*call, aktiv=True, f=f)),
|
|
("B Hintergrund+pid absolut", lambda: klick(*call, pid=f["pid"])),
|
|
("C Hintergrund+pid relativ", lambda: klick(*rel, pid=f["pid"]))):
|
|
stand = len(log()); sag("---", name, "---")
|
|
if not warte(stand): sag(" kein eigener Zug"); break
|
|
vorher = zeiger(); cmd(); time.sleep(5)
|
|
nach = zeiger(); neu = log()[stand:]
|
|
sag(" Zeiger", vorher, "->", nach, "| bewegt:", vorher != nach,
|
|
"| bestaetigt:", len(re.findall(r'"Cmd":"game\.user_action"', neu)),
|
|
"| Captions:", re.findall(r'"newCaption\\?":\\?"(\w+)\\"', neu)[-3:])
|