events_subscribe
Subscribe to real-time window state changes for continuous monitoring without polling. Track window appearances, disappearances, and focus changes with buffered events.
Instructions
Purpose: Subscribe to window-state change events (appear/disappear/focus) for continuous monitoring without repeated polling. Details: Returns subscriptionId. Events are buffered internally at 500ms intervals via EnumWindows; buffer holds up to 50 events (oldest dropped on overflow). Call events_poll(subscriptionId, sinceMs: lastEventTs) to drain incrementally; call events_unsubscribe when monitoring is complete. Each buffered event: {type, hwnd, title, timestamp}. Prefer: Use instead of wait_until(window_appears) when you need to monitor multiple events simultaneously or over an extended period. Use wait_until for one-shot, single-condition waiting. Caveats: Events that occurred before subscribe() was called will not appear — buffer starts empty. Poll frequently (every few seconds) during high-frequency window activity to avoid the 50-event overflow. Examples: id = events_subscribe() → poll: events_poll({subscriptionId:id}) → on next poll: events_poll({subscriptionId:id, sinceMs: lastEventTs}) → events_unsubscribe({subscriptionId:id})
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| types | No | Event types to listen for. |