From 0a983a3a171793340921541e0546437afd42c16f Mon Sep 17 00:00:00 2001 From: Demo_Liu Date: Mon, 31 May 2021 21:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=9A=E5=AE=89=EF=BC=8C=20=E8=BF=98?= =?UTF-8?q?=E5=9C=A8=E5=8A=9F=E8=83=BD=E6=80=A7=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Control/UserControls/LeftCardControl.xaml | 2 +- Control/UserControls/MotionControl.xaml | 10 +++++- Control/UserControls/MotionControl.xaml.cs | 32 ++++++++++++++--- GeekDesk.csproj | 3 ++ MainWindow.xaml.cs | 3 +- Util/HotKey.cs | 2 +- ViewModel/AppConfig.cs | 41 ++++++++++++++++++++++ packages.config | 1 + 8 files changed, 86 insertions(+), 8 deletions(-) diff --git a/Control/UserControls/LeftCardControl.xaml b/Control/UserControls/LeftCardControl.xaml index 08005eb..8439724 100644 --- a/Control/UserControls/LeftCardControl.xaml +++ b/Control/UserControls/LeftCardControl.xaml @@ -105,7 +105,7 @@ - - + @@ -56,6 +56,14 @@ + diff --git a/Control/UserControls/MotionControl.xaml.cs b/Control/UserControls/MotionControl.xaml.cs index 1deb809..dbccc76 100644 --- a/Control/UserControls/MotionControl.xaml.cs +++ b/Control/UserControls/MotionControl.xaml.cs @@ -23,16 +23,40 @@ namespace GeekDesk.Control.UserControls /// public partial class MotionControl : UserControl { + private static bool controlKeyDown = false; + private static AppConfig appConfig = MainWindow.appData.AppConfig; + public MotionControl() { InitializeComponent(); } - private void CheckBox_Unchecked(object sender, RoutedEventArgs e) + + /// + /// 热键按下 + /// + /// + /// + private void HotKeyDown(object sender, KeyEventArgs e) { - + if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt) + || (e.Key >= Key.A && e.Key <= Key.Z)) + { + if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt)) + { + appConfig.HotkeyStr = "Ctrl + "; + } else if (e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Control) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Windows) + || e.KeyboardDevice.Modifiers.HasFlag(ModifierKeys.Alt) + && (e.Key >= Key.A && e.Key <= Key.Z)) + { + appConfig.HotkeyStr += e.Key.ToString(); + } + } } - - } } diff --git a/GeekDesk.csproj b/GeekDesk.csproj index 388d143..73ae421 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -53,6 +53,9 @@ packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll + + packages\GlobalHotKey.1.1.0\lib\GlobalHotKey.dll + packages\HandyControl.3.1.0\lib\net452\HandyControl.dll diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index d480fc3..19eeaba 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using GeekDesk.Constant; using GeekDesk.Control; using GeekDesk.Util; using GeekDesk.ViewModel; +using GlobalHotKey; using SharpShell.SharpContextMenu; using System; using System.Collections.ObjectModel; @@ -53,7 +54,7 @@ namespace GeekDesk this.Visibility = Visibility.Collapsed; } //加载完毕注册热键 - Hotkey.Regist(this, HotkeyModifiers.MOD_CONTROL, Key.Y, ()=> + Hotkey.Regist(this, HotkeyModifiers.MOD_CONTROL | HotkeyModifiers.MOD_ALT, Key.Y, ()=> { if (this.Visibility == Visibility.Collapsed) { diff --git a/Util/HotKey.cs b/Util/HotKey.cs index 8f37695..60d0eb6 100644 --- a/Util/HotKey.cs +++ b/Util/HotKey.cs @@ -82,7 +82,7 @@ namespace GeekDesk.Util public delegate void HotKeyCallBackHanlder(); } - enum HotkeyModifiers + public enum HotkeyModifiers { MOD_ALT = 0x1, MOD_CONTROL = 0x2, diff --git a/ViewModel/AppConfig.cs b/ViewModel/AppConfig.cs index 09c6bb8..542064f 100644 --- a/ViewModel/AppConfig.cs +++ b/ViewModel/AppConfig.cs @@ -5,6 +5,7 @@ using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Windows; +using System.Windows.Input; using System.Windows.Media.Imaging; /// @@ -36,8 +37,48 @@ namespace GeekDesk.ViewModel private int pannelCornerRadius = 4; //面板圆角 默认4 [field: NonSerialized] private ObservableCollection selectedMenuIcons; + private string hotkeyStr; + private HotkeyModifiers hotkeyModifiers; + private Key hotkey; #region GetSet + public Key Hotkey + { + get + { + return hotkey; + } + set + { + hotkey = value; + OnPropertyChanged("Hotkey"); + } + } + public string HotkeyStr + { + get + { + return hotkeyStr; + } + set + { + hotkeyStr = value; + OnPropertyChanged("HotkeyStr"); + } + } + public HotkeyModifiers HotkeyModifiers + { + get + { + return hotkeyModifiers; + } + set + { + hotkeyModifiers = value; + OnPropertyChanged("HotkeyModifiers"); + } + } + public ObservableCollection SelectedMenuIcons { get diff --git a/packages.config b/packages.config index a284de5..774c9a1 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,7 @@  +