Why it happens
Windows treats all monitors as one continuous virtual desktop — a single coordinate space. With two 1920-px-wide displays, x runs from 0 to 3839. A fast flick in a game that uses the system cursor (many menus, some third-person and strategy titles, borderless-windowed FPS lobbies) simply slides x past 1919 into the neighbor screen.
Click while it's there and the game loses focus: on a taskbar, a browser, a stream chat. In CS2 or PUBG, a two-second alt-tab is usually a death.
Why fullscreen doesn't always save you
Exclusive fullscreen usually confines the cursor, but borderless windowed — the mode most players prefer for fast alt-tabbing — often doesn't, especially in menus, inventory screens, and map views where the real cursor comes back.
The one-call fix
Windows has had the answer since the 1990s: ClipCursor, a Win32 function that takes a rectangle and refuses to let the cursor leave it. A "cursor lock" utility is essentially:
- Read the target monitor's bounds (EnumDisplayMonitors / GetMonitorInfo).
- On hotkey toggle, call ClipCursor(&rect) with those bounds.
- On toggle-off (or on focus loss), call ClipCursor(NULL) to release.
That's why one person can build it in an evening. The subtle parts are re-applying the clip when Windows clears it (some system events reset it) and playing nicely when games call ClipCursor themselves.
Related mechanisms
Browsers use the Pointer Lock API (games get raw movement deltas, no cursor at all). Engines with raw input skip the cursor entirely for aiming — which is why your aim never escapes, only your menu cursor does.