Receive Key Messages irrespective of Key Modifiers
C#, Component Development, Win Forms October 30th, 2006As covered in a previous article, you can overrride the IsInputKey method on a control to inform winforms that you require keyboard event notification for special keys like tabe and cursor keys which are used but the hosting form for control navigation.
When writing a control, I was trying to capture the SHIFT - Right Cursor combination. I already had the following implementation in IsInputKey
switch (keyData)
{
case Keys.Up:
case Keys.Down:
case Keys.Left:
case Keys.Right:
case Keys.Home:
case Keys.End:
{
return true;
}
}
return base.IsInputKey(keyData);
However, althought control-Right and Alt-Right events came through Shift-Right wouldn’t. These were passed to the base implementation which returned true to be handled by the control but fals for the shift right.
So to force the processing of keys irrespective of the key modifiers simply chnage the case statement to read
switch (keyData & ~Keys.Modifiers)
Which removes and modifier bit flags from the keydata fro the switch comparison.
Recent Comments