Skip to content

Commit

Permalink
调通全局快捷键
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-luke committed Sep 21, 2021
1 parent c6bb676 commit 3635b28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CopyPlusPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
<PackageReference Include="Emoji.Wpf">
<Version>0.3.3</Version>
</PackageReference>
<PackageReference Include="GlobalHotKey">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf">
<Version>1.1.0</Version>
</PackageReference>
Expand Down
16 changes: 16 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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);
Expand Down

0 comments on commit 3635b28

Please sign in to comment.