Multiple hot key selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a ContextMenu that begs to have hot keys. I tried adding some but am
having issues understanding how to properly manage the events when dealing
with more than one key pressed (e.g., Alt-F1, Cntr-C) or even with F2. Can
someone point me to some documentation that explains how to properly handle
these type of keyboard inputs in ContextMenus?
 
If you are using the MenuItem controls, there is a "shortcut" property that
will take just about anything and trigger selection of that menu item. If
you set it through VS Properties box, you can just select from a list.
Otherwise, there is an enum called "Shortcut" that you can use for this (in
System.Windows.Forms, I think.)

If you want to handle everything manually, you'd probably need to use the
ProcessCmdKey(). Code inside would look something like this:

switch (keyData)
{
case Keys.F3:
HandleF3Press();
return true;
case Keys.Control | Keys.Up
HandleCtrlUpArrow();
return true;
case Keys.Alt | Keys.D1:
HandleAltOne();
return true;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
 
Back
Top