Enhance GlobalHotkeyService to allow for dynamic hotkey updates and improve user experience with customizable HotkeyModifiers and HotkeyVirtualKey settings.

This commit is contained in:
2026-02-22 12:14:57 -05:00
parent 742c1d70fe
commit 52a2515e2d
4 changed files with 27 additions and 12 deletions

View File

@@ -1,10 +1,12 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.Win32;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using Windows.System;
using WinRT.Interop;
namespace ClipForge
@@ -16,6 +18,7 @@ namespace ClipForge
private ClipLibraryService _clipLibrary;
private SettingsService _settingsService;
private ThumbnailService _thumbnailService;
private bool _isRecordingHotkey;
private delegate IntPtr WinProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
private WinProc _newWndProc;
@@ -41,6 +44,13 @@ namespace ClipForge
private static extern IntPtr SendMessage(IntPtr hWnd, uint msg,
IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vk);
private const int VK_SHIFT = 0x10;
private const int VK_CONTROL = 0x11;
private const int VK_MENU = 0x12; // Alt
private const int VK_LWIN = 0x5B;
private const int GWLP_WNDPROC = -4;
private const uint WM_HOTKEY = 0x0312;
private const int GWL_EXSTYLE = -20;
@@ -78,7 +88,10 @@ namespace ClipForge
_hotkeyService = new GlobalHotkeyService();
_hotkeyService.ClipRequested += OnClipRequested;
_hotkeyService.Initialize(hwnd);
var mod = _settingsService.Settings.HotkeyModifiers;
var vk = _settingsService.Settings.HotkeyVirtualKey;
if (mod == 0 && vk == 0) { mod = 1; vk = 0x78; }
_hotkeyService.Initialize(hwnd, (uint)mod, (uint)vk);
ClipGrid.ItemsSource = _clipLibrary.Clips;
UpdateClipCount();