winform直接&D就OK,还是没有winform方便。
方式1:
资源
输入快捷键与资源绑定
资源绑定调用操作
<Window.Resources>
<RoutedUICommand x:Key="download" Text="download"/>
</Window.Resources>
<Window.InputBindings>
<KeyBinding Gesture="Alt+D" Key="D" Command="{StaticResource download}"></KeyBinding>
</Window.InputBindings>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource download}" CanExecute="Button_Click"></CommandBinding>
</Window.CommandBindings>
方式2:
写控件或者窗体的KeyDown事件 PreviewKeyDown="Window_KeyDown"
//Alt+D
if ((e.KeyboardDevice.IsKeyDown(Key.LeftAlt) || e.KeyboardDevice.IsKeyDown(Key.RightAlt)) && e.KeyboardDevice.IsKeyDown(Key.D))
{
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement.GetType().Name == "TextBox") return;
Button_Click(null, null);
}