By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

KeyDown not capturing all keys

P: n/a
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

Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/lib...l.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.
-----------------------------------------------------------------------

ML****@hotmail.com wrote:
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
Sep 18 '06 #2

P: n/a
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?

DaanishRumani wrote:
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/lib...l.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.
-----------------------------------------------------------------------

ML****@hotmail.com wrote:
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
Sep 18 '06 #3

P: n/a
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...

ML****@hotmail.com wrote:
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
Sep 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.