My MDI application handles regular keystrokes (A-Z, 0-9 etc.) in keypress handler of Main window with KeyPreview = true
. It filters some sequences of incoming characters, hiding them from subsequent KeyPress
handlers. This works fine in MDI windows, but the Main window's KeyPress
is not invoked if modal window is active (because Main form is no longer focused). I open modal windows through simple ShowDialog()
.
Is there some way to universally catch and filter KeyPress events regardless of which application window has the focus (including modal windows?)
I'm searching for handling of KeyPresses on application level, not global level. => I don't want to be notified of KeyPresses if the application doesn't have focus.
This can be accomplished via IMessageFilter().
Here's a quick example: