Windows keyboard hook (SetWindowsHookExA) doesn't get called.
Simplified version:
It's doing "something" - when the application is running, key presses have some delay. What it's not doing however, is actually calling the Hook method. Any pointers?
3 Replies
what are you using hooks for?
or rather, why hooks?
@Sebastian
Your application needs a message loop to get messages. Also check if the _handle is 0, that means it failed You can get more info from the GetLastError
Like this https://github.com/JustArion/Win11_Tooltip_Fix/blob/master/src%2FTooltip_Fix%2FProgram.cs#L43-L50
Though that project used wineventhooks I'm pretty sure the same would apply for winhooks
The unmanaged function might be a blocking call, other hooks might need to wait for your code to finish executing to continue so your delegate might need to be transferred to another thread. That would also solve the issue of exceptions causing CallNextHookEx not to be called
Lastly the lParam is a pointer to the tagKBDLLHOOKSTRUCT struct, its not a ConsoleKey type (More info found here https://learn.microsoft.com/en-us/windows/win32/winmsg/lowlevelkeyboardproc)
I personally prefer H.Hooks for their
H.Hooks.LowLevelKeyboardHook
wrapperSorry for being inactive, life happens
Thank you! (handle is fine, I just need the message loop)