Files
pokerfreak/hand/press.py
T
mmintel 3674ee120a Scharfe Fassung pruefbar machen, ohne am Client zu frickeln
Zwei Faelle und eine Pruef-Doku - und sie haben zwei echte Fehler gefunden:

* tests/clientweg_spec.py: der Client-Weg, gefahren auf dem Klon in Client-Form (sichtbares
  Fenster, Fenster ueber System Events, Klick mit der Maus, Taste an den Prozess). Eigener Gang:
    clientweg_spec.py            ROT     3 Fälle  0 übersprungen   6.1s

3 Fälle in 6.1s | rot: 1
ECHTE EINGABE VERSUCHT (gesperrt):
clientweg_spec.py CGEventPost
clientweg_spec.py CGEventPost - schnell und kette bleiben headless.
* tests/client_material_spec.py: die Mitschriebe in archiv/ durch Leser und Entscheider
  (), ohne Tisch und Fenster, mit Abdeckungsbericht der Felder.
* docs/SCHARF-PRUEFUNG.md: was bewiesen ist, was nur am Client geht, die Live-Reihenfolge.

Gefunden und behoben:
* hand/tasten schickte die KeyCodes des Clients als virtuelle macOS-Codes - ueber die Tastatur kam
  damit die falsche Taste an. Jetzt umgerechnet (hand/press.py kennt die Codes); press.py ist
  dafuer als Modul benutzbar (der Import lief vorher ins Skript und beendete den Prozess).
* die Klon-Seite kannte nur die Codes des Debug-Port-Wegs und hoerte die physische Tastatur nicht.
* sichtbares Klonfenster hatte Standardgroesse: die Seite rechnet in vw/vh, das Tischlayout sass
  nicht mehr zueinander. Jetzt in der Groesse des Client-Fensters (1640x1256, aus den Bildern).
* tests/klonlauf.py und tests/lauf.py: sicht fehlte auf dem Suchpfad (steuern liegt dort).
2026-11-02 11:14:47 +01:00

74 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Tastendruck an das Tischfenster senden - ohne den Fokus zu klauen.
python3 press.py --trust # ist die Bedienungshilfen-Freigabe erteilt?
python3 press.py f # Taste 'f' an CoinPoker Game senden
python3 press.py --global f # stattdessen an das vorderste Fenster
"""
import os as _os, sys as _sys
_w = _os.path.dirname(_os.path.abspath(__file__))
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "lesen")):
_w = _os.path.dirname(_w)
WURZEL = _w
for _u in ("lesen", "entscheiden", "hand", "client", "lobby", "korpus", "betrieb"):
_q = _os.path.join(_w, _u)
if _os.path.isdir(_q) and _q not in _sys.path:
_sys.path.insert(0, _q)
import ctypes
import subprocess
import sys
FW = "/System/Library/Frameworks/ApplicationServices.framework/ApplicationServices"
AS = ctypes.cdll.LoadLibrary(FW)
AS.AXIsProcessTrusted.restype = ctypes.c_bool
AS.CGEventCreateKeyboardEvent.restype = ctypes.c_void_p
AS.CGEventCreateKeyboardEvent.argtypes = [ctypes.c_void_p, ctypes.c_uint16, ctypes.c_bool]
AS.CGEventPostToPid.argtypes = [ctypes.c_int, ctypes.c_void_p]
AS.CGEventPost.argtypes = [ctypes.c_uint32, ctypes.c_void_p]
# macOS Virtuelle Tastencodes
KEYS = {
"a": 0, "s": 1, "d": 2, "f": 3, "h": 4, "g": 5, "z": 6, "x": 7, "c": 8, "v": 9,
"b": 11, "q": 12, "w": 13, "e": 14, "r": 15, "y": 16, "t": 17, "o": 31, "u": 32,
"i": 34, "p": 35, "l": 37, "j": 38, "k": 40, "n": 45, "m": 46,
"1": 18, "2": 19, "3": 20, "4": 21, "5": 23, "6": 22, "7": 26, "8": 28, "9": 25,
"0": 29, "space": 49, "enter": 36, "esc": 53, "tab": 48,
}
def main():
while True:
out = subprocess.run(["pgrep", "-f", "CoinPoker Game"], capture_output=True, text=True)
pids = [int(x) for x in out.stdout.split()]
if not pids:
print("kein Tischfenster gefunden (CoinPoker Game laeuft nicht)")
sys.exit(1)
break
args = sys.argv[1:]
if not args or args[0] == "--trust":
print("Bedienungshilfen-Freigabe erteilt:", AS.AXIsProcessTrusted())
print("Tisch-Prozesse:", pids)
sys.exit(0)
global_mode = args[0] == "--global"
key = args[-1]
code = KEYS.get(key.lower())
if code is None:
print(f"unbekannte Taste {key!r}; bekannt: {sorted(KEYS)}")
sys.exit(1)
for down in (True, False):
event = AS.CGEventCreateKeyboardEvent(None, code, down)
if global_mode:
AS.CGEventPost(0, event)
else:
for pid in pids:
AS.CGEventPostToPid(pid, event)
print(f"Taste {key!r} (code {code}) gesendet an {pids}"
f"{' (global)' if global_mode else ' (an Prozess)'}")
if __name__ == "__main__":
main()