KeyDown not capturing all keys

M

MLM450

I have a control that handles the KeyDown event but it does not seem to
execute when a combination of keys is pressed - like CTRL+Z. If I
press CTRL, it executes. If I press Z, it executes. But the handler
does not see the combination.

Now this control is contained within another control which is contained
within another. The top most control does see the CTRL+Z. I can easily
pass down the key info, but why does the nested control see some keys
events and not others? It would be cleaner if the nested control simply
handled all input.

Thanks,
Mike
 
D

DaanishRumani

KeyDown Event does not handle all keys.

I quote the remark from MSDN help for the KeyDown Event located at:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.keydown.aspx
----------------------------------------------------------
Key events occur in the following order:

KeyDown

KeyPress

KeyUp

To handle keyboard events only at the form level and not enable other
controls to receive keyboard events, set the KeyPressEventArgs.Handled
property in your form's KeyPress event-handling method to true. Certain
keys, such as the TAB, RETURN, ESCAPE, and arrow keys are handled by
controls automatically. To have these keys raise the KeyDown event, you
must override the IsInputKey method in each control on your form. The
code for the override of the IsInputKey would need to determine if one
of the special keys is pressed and return a value of true.

For more information about handling events, see Consuming Events.
 
M

MLM450

Thanks for the reply, but this does not seem to apply to my situation.

1) Handling events at the form level...
I am not creating a windows form. It's a control used by other
developers. Also, I am trying to get the opposite effect.

2) Override the IsInputKey function...
This function only works on individual keys. As I stated, the
individual keys are fine. My control is not seeing the combination.

Any other ideas?
 
M

MLM450

I found that the control works fine when it is used within a C#
application. The problem occurs when it is used within a C++
application. It seems that simple keys like "Z" are routed to the
sub-control that has focus while the "CTRL+Z" key strokes are routed to
the topmost control. Strange...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top