As title says, you have wrong condition in the Dispose method of the KeystrokeAPI class.
It is supposed to be
if (globalKeyboardHookId != IntPtr.Zero)
User32.UnhookWindowsHookEx(globalKeyboardHookId);
instead of
if (globalKeyboardHookId == IntPtr.Zero)
User32.UnhookWindowsHookEx(globalKeyboardHookId);
Also the overall design of the class is quite easy to create handle leaks - e.g. call twice CreateKeyboardHook and you are no longer able to unhook the hook.
As title says, you have wrong condition in the
Disposemethod of theKeystrokeAPIclass.It is supposed to be
instead of
Also the overall design of the class is quite easy to create handle leaks - e.g. call twice
CreateKeyboardHookand you are no longer able to unhook the hook.