Add hotkey recording functionality in MainWindow. Users can now set custom hotkeys through a dedicated button, with real-time feedback on key presses and modifier keys. Updates to settings are reflected immediately.

This commit is contained in:
2026-02-22 12:15:50 -05:00
parent 52a2515e2d
commit 6aa49c0b07

View File

@@ -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)
{