-
Notifications
You must be signed in to change notification settings - Fork 5
Add modifier key support for global hotkey configuration #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dimitar-radenkov
merged 4 commits into
master
from
feature/configurable-record-hotkey-modifiers
Apr 30, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
63dc2d6
Add modifier key support for global hotkey configuration
dimitar-radenkov 9413167
Fix PR review: WM_SYSKEYDOWN for Alt hotkeys, XML doc, and modifier t…
dimitar-radenkov bbb818a
Fix Codecov upload: add CODECOV_TOKEN secret
dimitar-radenkov c701d8c
Improve patch coverage: add GlobalHotkeyService and SettingsWindow tests
dimitar-radenkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| using System.Reflection; | ||
| using Microsoft.Extensions.Logging.Abstractions; | ||
| using Moq; | ||
| using Pointframe.Models; | ||
| using Pointframe.Services; | ||
| using Xunit; | ||
|
|
||
| namespace Pointframe.Tests.Services; | ||
|
|
||
| public sealed class GlobalHotkeyServiceTests | ||
| { | ||
| private static GlobalHotkeyService CreateService(UserSettings? settings = null) | ||
| { | ||
| var mock = new Mock<IUserSettingsService>(); | ||
| mock.SetupGet(s => s.Current).Returns(settings ?? new UserSettings()); | ||
| return new GlobalHotkeyService(mock.Object, NullLogger<GlobalHotkeyService>.Instance); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void BeginKeyCaptureMode_StoresCallback() | ||
| { | ||
| var svc = CreateService(); | ||
| Action<uint, HotkeyModifiers> callback = (_, _) => { }; | ||
|
|
||
| svc.BeginKeyCaptureMode(callback); | ||
|
|
||
| var field = typeof(GlobalHotkeyService) | ||
| .GetField("_keyCaptureCallback", BindingFlags.Instance | BindingFlags.NonPublic); | ||
| Assert.NotNull(field); | ||
| Assert.Same(callback, field!.GetValue(svc)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void EndKeyCaptureMode_ClearsCallback() | ||
| { | ||
| var svc = CreateService(); | ||
| svc.BeginKeyCaptureMode((_, _) => { }); | ||
|
|
||
| svc.EndKeyCaptureMode(); | ||
|
|
||
| var field = typeof(GlobalHotkeyService) | ||
| .GetField("_keyCaptureCallback", BindingFlags.Instance | BindingFlags.NonPublic); | ||
| Assert.NotNull(field); | ||
| Assert.Null(field!.GetValue(svc)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Dispose_CanBeCalledMultipleTimes_DoesNotThrow() | ||
| { | ||
| var svc = CreateService(); | ||
| svc.Dispose(); | ||
| var ex = Record.Exception(svc.Dispose); | ||
| Assert.Null(ex); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(false, false, false, HotkeyModifiers.None, true)] | ||
| [InlineData(true, false, false, HotkeyModifiers.Ctrl, true)] | ||
| [InlineData(true, true, false, HotkeyModifiers.Ctrl | HotkeyModifiers.Shift, true)] | ||
| [InlineData(true, true, true, HotkeyModifiers.Ctrl | HotkeyModifiers.Shift | HotkeyModifiers.Alt, true)] | ||
| [InlineData(true, false, false, HotkeyModifiers.None, false)] | ||
| [InlineData(false, false, false, HotkeyModifiers.Ctrl, false)] | ||
| [InlineData(true, true, false, HotkeyModifiers.Ctrl, false)] | ||
| public void ModifiersMatch_ReturnsExpected(bool ctrl, bool shift, bool alt, HotkeyModifiers required, bool expected) | ||
| { | ||
| var method = typeof(GlobalHotkeyService) | ||
| .GetMethod("ModifiersMatch", BindingFlags.Static | BindingFlags.NonPublic); | ||
| Assert.NotNull(method); | ||
|
|
||
| var result = (bool)method!.Invoke(null, [required, ctrl, shift, alt])!; | ||
|
|
||
| Assert.Equal(expected, result); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(NativeMethods.VK_SHIFT, true)] | ||
| [InlineData(NativeMethods.VK_LSHIFT, true)] | ||
| [InlineData(NativeMethods.VK_RSHIFT, true)] | ||
| [InlineData(NativeMethods.VK_LCONTROL, true)] | ||
| [InlineData(NativeMethods.VK_RCONTROL, true)] | ||
| [InlineData(NativeMethods.VK_LMENU, true)] | ||
| [InlineData(NativeMethods.VK_RMENU, true)] | ||
| [InlineData(NativeMethods.VK_LWIN, true)] | ||
| [InlineData(NativeMethods.VK_RWIN, true)] | ||
| [InlineData(0x41u, false)] // 'A' — not a modifier | ||
| [InlineData(NativeMethods.VK_ESCAPE, false)] | ||
| public void IsModifierVk_ReturnsExpected(uint vk, bool expected) | ||
| { | ||
| var method = typeof(GlobalHotkeyService) | ||
| .GetMethod("IsModifierVk", BindingFlags.Static | BindingFlags.NonPublic); | ||
| Assert.NotNull(method); | ||
|
|
||
| var result = (bool)method!.Invoke(null, [vk])!; | ||
|
|
||
| Assert.Equal(expected, result); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests cover that a captured key is stored, but don’t verify the new modifier behavior introduced by the callback signature. Consider asserting that RegionCaptureHotkeyModifiers is updated when a non-None modifier set is passed, and adding a similar test for OnRecordHotkeyKeyPressed to ensure record hotkey modifiers are persisted to the view model.