Messkript Eingabe: Kopf nachgereicht (Datei war beim Kopieren leer)
This commit is contained in:
@@ -413,7 +413,7 @@ class Beenden(unittest.TestCase):
|
|||||||
self._spielplan("uebung", 2, ["T1"], {"T1": frei})
|
self._spielplan("uebung", 2, ["T1"], {"T1": frei})
|
||||||
self.addCleanup(lambda: os.path.exists(runner.EINGRIFF) and os.remove(runner.EINGRIFF))
|
self.addCleanup(lambda: os.path.exists(runner.EINGRIFF) and os.remove(runner.EINGRIFF))
|
||||||
m = self.s.maschine
|
m = self.s.maschine
|
||||||
m.fenster() # T1 hat ein Fenster: aktiv
|
m.log(""); m.fenster() # T1 im Log und mit Fenster: aktiv
|
||||||
m.fuettern(runner.tischzustand.Geklickt("T1", "plus", time.time(), sitz=2, stelle=2, quelle="sicher"))
|
m.fuettern(runner.tischzustand.Geklickt("T1", "plus", time.time(), sitz=2, stelle=2, quelle="sicher"))
|
||||||
self.assertIsNotNone(m.z.plus("T1"))
|
self.assertIsNotNone(m.z.plus("T1"))
|
||||||
with open(runner.EINGRIFF, "w") as f:
|
with open(runner.EINGRIFF, "w") as f:
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Messung: erreicht ein Klick an den Prozess (pid) den echten Tisch?
|
||||||
|
|
||||||
|
Drei Varianten, jede wartet auf einen eigenen Zug (deshalb 2-4 Minuten):
|
||||||
|
A Fenster aktiviert + globaler Klick - Kontrolle (so klickt der Bot 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 echte
|
||||||
|
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")
|
||||||
|
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:])
|
||||||
|
|||||||
Reference in New Issue
Block a user