diff --git a/KeyboardChatterBlocker/KeyboardInterceptor.cs b/KeyboardChatterBlocker/KeyboardInterceptor.cs
index 80f6fe8..49296b3 100644
--- a/KeyboardChatterBlocker/KeyboardInterceptor.cs
+++ b/KeyboardChatterBlocker/KeyboardInterceptor.cs
@@ -86,7 +86,18 @@ public KeyboardInterceptor(KeyBlocker blocker)
KeyBlockHandler = blocker;
KeyboardProcCallback = KeyboardHookCallback;
MouseProcCallback = MouseHookCallback;
- KeyboardHookID = SetKeyboardHook(KeyboardProcCallback);
+ EnableKeyboardHook();
+ }
+
+ ///
+ /// Enables the keyboard hook (if not already enabled).
+ ///
+ public void EnableKeyboardHook()
+ {
+ if (KeyboardHookID == IntPtr.Zero)
+ {
+ KeyboardHookID = SetKeyboardHook(KeyboardProcCallback);
+ }
}
///
@@ -300,15 +311,23 @@ public void DisableMouseHook()
}
///
- /// Dispose the object, removing the hook.
+ /// Disables the keyboard hook (to fully disable when Auto-Disable Programs are used).
///
- protected virtual void Dispose(bool disposing)
+ public void DisableKeyboardHook()
{
if (KeyboardHookID != IntPtr.Zero)
{
UnhookWindowsHookEx(KeyboardHookID);
KeyboardHookID = IntPtr.Zero;
}
+ }
+
+ ///
+ /// Dispose the object, removing the hook.
+ ///
+ protected virtual void Dispose(bool disposing)
+ {
+ DisableKeyboardHook();
DisableMouseHook();
}
diff --git a/KeyboardChatterBlocker/MainBlockerForm.cs b/KeyboardChatterBlocker/MainBlockerForm.cs
index e8ecf8d..e103059 100644
--- a/KeyboardChatterBlocker/MainBlockerForm.cs
+++ b/KeyboardChatterBlocker/MainBlockerForm.cs
@@ -162,11 +162,15 @@ public void SetAutoDisable(bool disable)
Program.Blocker.IsAutoDisabled = disable;
if (disable)
{
+ Program.Blocker.Interceptor.DisableKeyboardHook();
+ Program.Blocker.Interceptor.DisableMouseHook();
EnableNoteLabel.Text = "(Automatically disabled due to an open process)";
EnableNoteLabel.BackColor = Color.FromArgb(64, 255, 0, 0);
}
else
{
+ Program.Blocker.Interceptor.EnableKeyboardHook();
+ Program.Blocker.AutoEnableMouse();
EnableNoteLabel.Text = "";
EnableNoteLabel.BackColor = Color.Transparent;
foreach (string notBlocking in Program.Blocker.AutoDisablePrograms)