diff --git a/CopyPlusPlus.csproj b/CopyPlusPlus.csproj index f01960b..b839725 100644 --- a/CopyPlusPlus.csproj +++ b/CopyPlusPlus.csproj @@ -221,6 +221,9 @@ 0.3.3 + + 1.1.0 + 1.1.0 diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index cd59941..0cd9648 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -20,6 +20,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using GlobalHotKey; //using WK.Libraries.SharpClipboardNS; //.net framework 4.6 not supported @@ -49,6 +50,9 @@ public partial class MainWindow : MetroWindow public static RoutedCommand Paste = new RoutedCommand(); public static RoutedCommand Trans = new RoutedCommand(); + // Create the hotkey manager. + public HotKeyManager hotKeyManager = new HotKeyManager(); + public MainWindow() { InitializeComponent(); @@ -57,6 +61,12 @@ public MainWindow() NotifyIcon = (TaskbarIcon)FindResource("MyNotifyIcon"); NotifyIcon.Visibility = Visibility.Collapsed; + // Register Ctrl+Alt+F5 hotkey. Save this variable somewhere for the further unregistering. + var hotKey = hotKeyManager.Register(Key.F5, ModifierKeys.Control | ModifierKeys.Alt); + + // Handle hotkey presses. + hotKeyManager.KeyPressed += HotKeyManagerPressed; + //快捷键 Copy.InputGestures.Add(new KeyGesture(Key.C, ModifierKeys.Control)); Paste.InputGestures.Add(new KeyGesture(Key.V, ModifierKeys.Control)); @@ -83,6 +93,12 @@ public MainWindow() TransEngineComboBox.SelectedIndex = Convert.ToInt32(checkList[10]); } + private void HotKeyManagerPressed(object sender, KeyPressedEventArgs e) + { + if (e.HotKey.Key == Key.F5) + MessageBox.Show("Hot key pressed!"); + } + protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e);