How do you keep global keyboard shortcuts from breaking text input and accessibility?

What’s up everyone? I’m wiring up global keyboard shortcuts for a web app (think cmd+k, /, esc) and I’m trying to do it without wrecking normal typing in inputs, contenteditable, or screen reader flows.

Right now it feels like a tradeoff between “catch everything reliably” (keydown on window + capture + preventDefault) and “don’t be a jerk” (let native behavior through), and I’m worried about edge cases like IME composition, repeated keydown, and shortcuts firing while focus is inside a dialog or embedded widget; what event handling pattern do you use to keep this reliable without accumulating brittle exceptions?