Key combinations are a fancy pair of words to describe pressing/holding multiple keyboard buttons to perform a command.
Ex:- Few of ever using key combinations are,
There are many such combinations, and while I provided some common ones, many applications like Visual Studio provide their own key combinations to help save you some time. Let's add some key combinations to our little program also.- Ctrl + S to Save,
- Ctrl + C to Copy,
- Alt + F4 to close an application,
- Ctrl + Alt + Del to lock our computer, etc.,
void SpecialKeyHandler(object sender, KeyEventArgs e)
{
// Ctrl + N
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.N))
{
MessageBox.Show("New");
}
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.O))
{
MessageBox.Show("Open");
}
// Ctrl + S
if ((Keyboard.Modifiers == ModifierKeys.Control) && (e.Key == Key.S))
{
MessageBox.Show("Save");
}
if ((Keyboard.Modifiers == (ModifierKeys.Alt | ModifierKeys.Control)) && (e.Key == Key.I))
{
MessageBox.Show("Ctrl + Alt + I");
}
}
|