You need to try something similar to this
private void AddHotKeys()
{
try
{
RoutedCommand firstSettings = new RoutedCommand();
firstSettings.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Alt));
CommandBindings.Add(new CommandBinding(firstSettings , My_first_event_handler));
RoutedCommand secondSettings = new RoutedCommand();
secondSettings.InputGestures.Add(new KeyGesture(Key.B, ModifierKeys.Alt));
CommandBindings.Add(new CommandBinding(secondSettings , My_second_event_handler));
}
catch (Exception err)
{
//handle exception error
}
}
Events
private void My_first_event_handler(object sender, ExecutedRoutedEventArgs e)
{
//handler code goes here.
MessageBox.Show("Alt+A key pressed");
}
private void My_second_event_handler(object sender, RoutedEventArgs e)
{
//handler code goes here.
MessageBox.Show("Alt+B key pressed");
}
If you are following MVVM you could try this reference
<UserControl.InputBindings>
<KeyBinding Modifiers="Control"
Key="E"
Command="{input:CommandBinding EditCommand}"/>
See the reference
msdn adding key bindings