fix non-elevated auto click

This commit is contained in:
DismissedLight
2023-09-23 15:11:08 +08:00
parent 6029acc7f1
commit 4fb997c8d0
2 changed files with 15 additions and 2 deletions

View File

@@ -16,24 +16,36 @@ internal sealed class HotKeyController : IHotKeyController
private readonly object locker = new(); private readonly object locker = new();
private readonly WaitCallback runMouseClickRepeatForever; private readonly WaitCallback runMouseClickRepeatForever;
private readonly HotKeyOptions hotKeyOptions; private readonly HotKeyOptions hotKeyOptions;
private readonly RuntimeOptions runtimeOptions;
private volatile CancellationTokenSource? cancellationTokenSource; private volatile CancellationTokenSource? cancellationTokenSource;
public HotKeyController(IServiceProvider serviceProvider) public HotKeyController(IServiceProvider serviceProvider)
{ {
hotKeyOptions = serviceProvider.GetRequiredService<HotKeyOptions>(); hotKeyOptions = serviceProvider.GetRequiredService<HotKeyOptions>();
runtimeOptions = serviceProvider.GetRequiredService<RuntimeOptions>();
runMouseClickRepeatForever = MouseClickRepeatForever; runMouseClickRepeatForever = MouseClickRepeatForever;
} }
public bool Register(in HWND hwnd) public bool Register(in HWND hwnd)
{
if (runtimeOptions.IsElevated)
{ {
return RegisterHotKey(hwnd, DefaultId, default, (uint)VIRTUAL_KEY.VK_F8); return RegisterHotKey(hwnd, DefaultId, default, (uint)VIRTUAL_KEY.VK_F8);
} }
return false;
}
public bool Unregister(in HWND hwnd) public bool Unregister(in HWND hwnd)
{
if (runtimeOptions.IsElevated)
{ {
return UnregisterHotKey(hwnd, DefaultId); return UnregisterHotKey(hwnd, DefaultId);
} }
return false;
}
public void OnHotKeyPressed(in HotKeyParameter parameter) public void OnHotKeyPressed(in HotKeyParameter parameter)
{ {
if (parameter is { Key: VIRTUAL_KEY.VK_F8, Modifier: 0 }) if (parameter is { Key: VIRTUAL_KEY.VK_F8, Modifier: 0 })

View File

@@ -8,6 +8,7 @@ namespace Snap.Hutao.Core.Windowing.HotKey;
internal interface IHotKeyController internal interface IHotKeyController
{ {
void OnHotKeyPressed(in HotKeyParameter parameter); void OnHotKeyPressed(in HotKeyParameter parameter);
bool Register(in HWND hwnd); bool Register(in HWND hwnd);
bool Unregister(in HWND hwnd); bool Unregister(in HWND hwnd);