diff --git a/ClipForge/MainWindow.xaml.cs b/ClipForge/MainWindow.xaml.cs index 510dacf..6e57291 100644 --- a/ClipForge/MainWindow.xaml.cs +++ b/ClipForge/MainWindow.xaml.cs @@ -182,6 +182,8 @@ namespace ClipForge QualityLabel.Text = $"{s.VideoQuality}%"; FramerateCombo.SelectedIndex = s.Framerate == 30 ? 0 : 1; StartupToggle.IsOn = IsStartupEnabled(); + if (HotkeyRecorderText != null) + HotkeyRecorderText.Text = HotkeyHelper.ToDisplayString((uint)s.HotkeyModifiers, (uint)s.HotkeyVirtualKey); } // --- STARTUP WITH WINDOWS --- @@ -248,6 +250,42 @@ namespace ClipForge _ = ShowToastAsync("✅ Settings saved!"); } + // --- CUSTOM HOTKEY --- + private void HotkeyRecorderButton_Click(object sender, RoutedEventArgs e) + { + if (_isRecordingHotkey) return; + _isRecordingHotkey = true; + HotkeyRecorderText.Text = "Press any key..."; + this.KeyDown += OnHotkeyCaptureKeyDown; + } + + private void OnHotkeyCaptureKeyDown(object sender, KeyRoutedEventArgs e) + { + if (!_isRecordingHotkey) return; + e.Handled = true; + + var key = e.Key; + if (HotkeyHelper.IsModifierKey(key)) + return; // wait for a non-modifier key + + uint mod = 0; + if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0) mod |= HotkeyHelper.MOD_CONTROL; + if ((GetAsyncKeyState(VK_MENU) & 0x8000) != 0) mod |= HotkeyHelper.MOD_ALT; + if ((GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0) mod |= HotkeyHelper.MOD_SHIFT; + if ((GetAsyncKeyState(VK_LWIN) & 0x8000) != 0) mod |= HotkeyHelper.MOD_WIN; + + uint vk = (uint)key; + _settingsService.Settings.HotkeyModifiers = (int)mod; + _settingsService.Settings.HotkeyVirtualKey = (int)vk; + + var ok = _hotkeyService.UpdateHotkey(mod, vk); + var display = HotkeyHelper.ToDisplayString(mod, vk); + HotkeyRecorderText.Text = ok ? display : display + " (in use?)"; + + this.KeyDown -= OnHotkeyCaptureKeyDown; + _isRecordingHotkey = false; + } + // --- NAV --- private void NavClips_Click(object sender, RoutedEventArgs e) {