Capture all Key Press events

Capture all Key Press events

Post by chri » Fri, 07 Nov 2003 18:36:13

Does anyone know of an elegant approach to capture all keypress events
on a form no matter what control is active?
Basically I have a PPC with hardware key pad and I always want the
KeyPress to affect a certain control.


Capture all Key Press events

Post by Peter » Fri, 07 Nov 2003 22:27:52

There is no "event passing" as there is in Delphi (correct me if I am
wrong), where an event would be passed from an active control to the
underlying form (or other parent container) if the control didn't have that
specific event. As far as I know, you need to add the event to all focusable
controls if you want to make sure it fires no matter what control is

Another problem with the current version of compact framework is that many
controls don't even support key press events (such as the combobox), which
has caused a lot of trouble for developers who are using managed code and
not as familiar with low level hooking etc. Luckily, Service Pack 2 for the
compact framework will add key press support to most controls.

Hope that answers your question.

/ Peter


Capture all Key Press events

Post by Malone » Fri, 07 Nov 2003 23:24:47

Use RegisterHotKey to get when the hardware buttons are pressed. Take a
look at

Capture all Key Press events

Post by Ginny Cau » Sat, 08 Nov 2003 00:00:46


Take a look at the MessageWindow class. You can use it to catch Windows
messages and then dispatch the ones you're interested in to your form.
Whether this solution is elegant or not I'll leave for you to decide. ;-)
Here's a link to the QuickStart tutorial that describes it:
Ginny Caughey
.Net Compact Framework MVP