mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-05 04:39:08 +08:00
Added step to dispose the keyboard hook object (#4449)
This commit is contained in:
parent
ca99f60964
commit
2104a1250e
@ -25,6 +25,12 @@ KeyboardHook::KeyboardHook(
|
||||
KeyboardHook::~KeyboardHook()
|
||||
{
|
||||
quit = true;
|
||||
|
||||
// Notify the DispatchProc thread so that it isn't stuck at the Wait step
|
||||
Monitor::Enter(queue);
|
||||
Monitor::Pulse(queue);
|
||||
Monitor::Exit(queue);
|
||||
|
||||
kbEventDispatch->Join();
|
||||
|
||||
// Unregister low level hook procedure
|
||||
|
@ -49,5 +49,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose the KeyboardHook object to terminate the hook threads
|
||||
hook.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using System;
|
||||
using System.Data;
|
||||
|
||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
@ -54,9 +55,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
|
||||
HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
|
||||
HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus;
|
||||
HotkeyTextBox.Unloaded += HotkeyTextBox_Unloaded;
|
||||
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive);
|
||||
}
|
||||
|
||||
private void HotkeyTextBox_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Dispose the HotkeySettingsControlHook object to terminate the hook threads when the textbox is unloaded
|
||||
hook.Dispose();
|
||||
}
|
||||
|
||||
private void KeyEventHandler(int key, bool matchValue, int matchValueCode, string matchValueText)
|
||||
{
|
||||
switch ((Windows.System.VirtualKey)key)
|
||||
|
Loading…
Reference in New Issue
Block a user