Simply handle any of the "key" events on your controls or your Form. I recommend the Form, and then set the Form.KeyPreview property to true so that the form gets a change to handle the key sequences before the controls do, giving you a single point of "key" event handling. Now, modifiers like Shift and Ctrl don't raise events like Control.KeyDown, but you can get them easily through the Control.ModifierKeys static property, or - depending on which event you use - from the KeyEventArgs that is passed to your event handler. So, change the KeyPreview event on your form to true. Create a new event handler for the KeyDown event (or the KeyUp or KeyPress events), and do something like the following:
private void MyForm_KeyDown(object sender,
KeyEventArgs e)
{
if (e.KeyCode == Keys.X && e.Control)
{
e.Handled = true; // Don't let child controls process this
this.Close(); // Close your form or use Application.Exit()
}
}
If you wanted to support user-defineable combos, just pass the KeyEventArgs or part of its data through some key map that wouldn't be hard to create (see the Keys enumeration, which might help).
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----