mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Revert Hotkey from InputBinding back to KeyDown event
This commit is contained in:
parent
2efcbd060a
commit
1b4cc556be
@ -20,38 +20,6 @@
|
|||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
Visibility="{Binding IsVisible,Converter={converters:VisibilityConverter}}"
|
Visibility="{Binding IsVisible,Converter={converters:VisibilityConverter}}"
|
||||||
PreviewKeyDown="Window_PreviewKeyDown" d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
PreviewKeyDown="Window_PreviewKeyDown" d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
||||||
<Window.InputBindings>
|
|
||||||
<KeyBinding Key="Esc" Command="{Binding EscCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="Tab" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="N" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="J" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="Tab" Modifiers="Shift" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="P" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="K" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding CtrlOCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="D" Modifiers="Ctrl" Command="{Binding SelectNextPageCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="U" Modifiers="Ctrl" Command="{Binding SelectPrevPageCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding ShiftEnterCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="Enter" Modifiers="Ctrl" Command="{Binding OpenResultCommand}"></KeyBinding>
|
|
||||||
<KeyBinding Key="Enter" Modifiers="Alt" Command="{Binding OpenResultCommand}"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="D1" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="0"></KeyBinding>
|
|
||||||
<KeyBinding Key="D2" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="1"></KeyBinding>
|
|
||||||
<KeyBinding Key="D3" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="2"></KeyBinding>
|
|
||||||
<KeyBinding Key="D4" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="3"></KeyBinding>
|
|
||||||
<KeyBinding Key="D5" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="4"></KeyBinding>
|
|
||||||
<KeyBinding Key="D6" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="5"></KeyBinding>
|
|
||||||
|
|
||||||
<KeyBinding Key="Back" Command="{Binding BackCommand}"></KeyBinding>
|
|
||||||
</Window.InputBindings>
|
|
||||||
<Window.Resources>
|
<Window.Resources>
|
||||||
<DataTemplate DataType="{x:Type vm:ResultPanelViewModel}">
|
<DataTemplate DataType="{x:Type vm:ResultPanelViewModel}">
|
||||||
<wox:ResultPanel></wox:ResultPanel>
|
<wox:ResultPanel></wox:ResultPanel>
|
||||||
|
@ -159,12 +159,53 @@ namespace Wox
|
|||||||
|
|
||||||
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
|
private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
//The code here is to supress the conflict of Window.InputBinding and ListBox/TextBox native Key handle
|
|
||||||
var vm = this.DataContext as MainViewModel;
|
var vm = this.DataContext as MainViewModel;
|
||||||
|
|
||||||
|
if (null == vm) return;
|
||||||
//when alt is pressed, the real key should be e.SystemKey
|
//when alt is pressed, the real key should be e.SystemKey
|
||||||
Key key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
var key = (e.Key == Key.System ? e.SystemKey : e.Key);
|
||||||
switch (key)
|
switch (key)
|
||||||
{
|
{
|
||||||
|
case Key.Escape:
|
||||||
|
vm.EscCommand.Execute(null);
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Tab:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
vm.SelectPrevItemCommand.Execute(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.SelectNextItemCommand.Execute(null);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.N:
|
||||||
|
case Key.J:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
vm.SelectNextItemCommand.Execute(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.P:
|
||||||
|
case Key.K:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
vm.SelectPrevItemCommand.Execute(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.O:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
vm.CtrlOCommand.Execute(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Key.Down:
|
case Key.Down:
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
{
|
{
|
||||||
@ -188,17 +229,93 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Key.D:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
vm.SelectNextPageCommand.Execute(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Key.PageDown:
|
case Key.PageDown:
|
||||||
vm.SelectNextPageCommand.Execute(null);
|
vm.SelectNextPageCommand.Execute(null);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Key.U:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
||||||
|
{
|
||||||
|
vm.SelectPrevPageCommand.Execute(null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Key.PageUp:
|
case Key.PageUp:
|
||||||
vm.SelectPrevPageCommand.Execute(null);
|
vm.SelectPrevPageCommand.Execute(null);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.Back:
|
case Key.Back:
|
||||||
vm.BackCommand.Execute(e);
|
vm.BackCommand.Execute(e);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Key.F1:
|
||||||
|
vm.StartHelpCommand.Execute(null);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.Enter:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
||||||
|
{
|
||||||
|
vm.ShiftEnterCommand.Execute(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(null);
|
||||||
|
}
|
||||||
|
e.Handled = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D1:
|
||||||
|
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D2:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D3:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D4:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(3);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Key.D5:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(4);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Key.D6:
|
||||||
|
if (GlobalHotkey.Instance.CheckModifiers().AltPressed)
|
||||||
|
{
|
||||||
|
vm.OpenResultCommand.Execute(5);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user