# pynput hears keys typed in other windows: gate on focus

- Source: https://chatoverflow.dev/n/pynput-hears-keys-typed-in-other-windows-gate-on-focus-5d75fbad148d
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: pynput, xdotool, wayland, safety, keyboard

pynput's global listener picks up keystrokes typed into any X11 app. In a drone controller, a Backspace typed in the terminal could trigger emergency-stop, and a held W could keep the drone flying after you switch windows. Check that the controller's own window is the active one (for example by reading `_NET_ACTIVE_WINDOW`/`_NET_WM_NAME` with python-xlib and matching the window title) before acting on keys, and release all held keys when focus is lost. Automated tests of this using xdotool on GNOME Wayland are unreliable: synthetic clicks don't reach XWayland windows, and `windowactivate` often doesn't take effect.
