mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 20:57:22 +02:00
Hotkey for mainwindow
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
Topmost="True"
|
Topmost="True"
|
||||||
Loaded="OnLoaded"
|
Loaded="OnLoaded"
|
||||||
Closing="OnClosing"
|
Closing="OnClosing"
|
||||||
PreviewKeyDown="OnPreviewKeyDown"
|
|
||||||
Drop="OnDrop"
|
Drop="OnDrop"
|
||||||
Deactivated="OnDeactivated"
|
Deactivated="OnDeactivated"
|
||||||
SizeToContent="Height"
|
SizeToContent="Height"
|
||||||
@@ -25,6 +24,32 @@
|
|||||||
Top="{Binding Top, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
Top="{Binding Top, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||||
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||||
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
d:DataContext="{d:DesignInstance vm:MainViewModel}">
|
||||||
|
<Window.InputBindings>
|
||||||
|
<KeyBinding Key="Escape" Command="{Binding EscCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="F1" Command="{Binding StartHelpCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Tab" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Tab" Modifiers="Shift" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Down" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Up" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="N" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="J" Modifiers="Ctrl" Command="{Binding SelectNextItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="D" Modifiers="Ctrl" Command="{Binding SelectNextPageCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="P" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="K" Modifiers="Ctrl" Command="{Binding SelectPrevItemCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="U" Modifiers="Ctrl" Command="{Binding SelectPrevPageCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="O" Modifiers="Ctrl" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Enter" Modifiers="Shift" Command="{Binding LoadContextMenuCommand}"></KeyBinding>
|
||||||
|
<KeyBinding Key="Enter" 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="D7" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="6"></KeyBinding>
|
||||||
|
<KeyBinding Key="D8" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="7"></KeyBinding>
|
||||||
|
<KeyBinding Key="D9" Modifiers="Alt" Command="{Binding OpenResultCommand}" CommandParameter="8"></KeyBinding>
|
||||||
|
</Window.InputBindings>
|
||||||
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown">
|
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown">
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<TextBox Style="{DynamicResource QueryBoxStyle}"
|
<TextBox Style="{DynamicResource QueryBoxStyle}"
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ using Wox.Core.Plugin;
|
|||||||
using Wox.Core.Resource;
|
using Wox.Core.Resource;
|
||||||
using Wox.Core.UserSettings;
|
using Wox.Core.UserSettings;
|
||||||
using Wox.Helper;
|
using Wox.Helper;
|
||||||
using Wox.Infrastructure.Hotkey;
|
|
||||||
using Wox.ViewModel;
|
using Wox.ViewModel;
|
||||||
using ContextMenu = System.Windows.Forms.ContextMenu;
|
using ContextMenu = System.Windows.Forms.ContextMenu;
|
||||||
using DataFormats = System.Windows.DataFormats;
|
using DataFormats = System.Windows.DataFormats;
|
||||||
using DragEventArgs = System.Windows.DragEventArgs;
|
using DragEventArgs = System.Windows.DragEventArgs;
|
||||||
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
|
|
||||||
using MenuItem = System.Windows.Forms.MenuItem;
|
using MenuItem = System.Windows.Forms.MenuItem;
|
||||||
using MessageBox = System.Windows.MessageBox;
|
using MessageBox = System.Windows.MessageBox;
|
||||||
|
|
||||||
@@ -162,162 +160,6 @@ namespace Wox
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPreviewKeyDown(object sender, KeyEventArgs e)
|
|
||||||
{
|
|
||||||
var vm = DataContext as MainViewModel;
|
|
||||||
if (null == vm) return;
|
|
||||||
//when alt is pressed, the real key should be e.SystemKey
|
|
||||||
var key = (e.Key == Key.System ? e.SystemKey : e.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.LoadContextMenuCommand.Execute(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.Enter:
|
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().ShiftPressed)
|
|
||||||
{
|
|
||||||
vm.LoadContextMenuCommand.Execute(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.OpenResultCommand.Execute(null);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.Down:
|
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
||||||
{
|
|
||||||
vm.DisplayNextQueryCommand.Execute(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.SelectNextItemCommand.Execute(null);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.Up:
|
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
||||||
{
|
|
||||||
vm.DisplayPrevQueryCommand.Execute(null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
vm.SelectPrevItemCommand.Execute(null);
|
|
||||||
}
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.D:
|
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
||||||
{
|
|
||||||
vm.SelectNextPageCommand.Execute(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.PageDown:
|
|
||||||
vm.SelectNextPageCommand.Execute(null);
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.U:
|
|
||||||
if (GlobalHotkey.Instance.CheckModifiers().CtrlPressed)
|
|
||||||
{
|
|
||||||
vm.SelectPrevPageCommand.Execute(null);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.PageUp:
|
|
||||||
vm.SelectPrevPageCommand.Execute(null);
|
|
||||||
e.Handled = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Key.F1:
|
|
||||||
vm.StartHelpCommand.Execute(null);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
|
private void OnPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (sender != null && e.OriginalSource != null)
|
if (sender != null && e.OriginalSource != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user