mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
Added step to dispose the keyboard hook object (#4449)
This commit is contained in:
@@ -25,6 +25,12 @@ KeyboardHook::KeyboardHook(
|
|||||||
KeyboardHook::~KeyboardHook()
|
KeyboardHook::~KeyboardHook()
|
||||||
{
|
{
|
||||||
quit = true;
|
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();
|
kbEventDispatch->Join();
|
||||||
|
|
||||||
// Unregister low level hook procedure
|
// Unregister low level hook procedure
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using interop;
|
|||||||
namespace Microsoft.PowerToys.Settings.UI.Lib
|
namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||||
{
|
{
|
||||||
public delegate void KeyEvent(int key);
|
public delegate void KeyEvent(int key);
|
||||||
|
|
||||||
public delegate bool IsActive();
|
public delegate bool IsActive();
|
||||||
|
|
||||||
public class HotkeySettingsControlHook
|
public class HotkeySettingsControlHook
|
||||||
@@ -49,5 +49,11 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
|||||||
break;
|
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.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
using Windows.UI.Xaml.Input;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
|
||||||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
|
||||||
namespace Microsoft.PowerToys.Settings.UI.Controls
|
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||||
@@ -54,9 +55,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
|||||||
|
|
||||||
HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
|
HotkeyTextBox.GettingFocus += HotkeyTextBox_GettingFocus;
|
||||||
HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus;
|
HotkeyTextBox.LosingFocus += HotkeyTextBox_LosingFocus;
|
||||||
|
HotkeyTextBox.Unloaded += HotkeyTextBox_Unloaded;
|
||||||
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive);
|
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)
|
private void KeyEventHandler(int key, bool matchValue, int matchValueCode, string matchValueText)
|
||||||
{
|
{
|
||||||
switch ((Windows.System.VirtualKey)key)
|
switch ((Windows.System.VirtualKey)key)
|
||||||
|
|||||||
Reference in New Issue
Block a user