Page 1 of 1
Keyboard hooks; called twice?
Posted: Fri Jun 17, 2011 3:48 pm
by jassing
I installed a keyboard hook; but for each key press, it seems to fire twice (I'm guessing responding to down/up state)
A bit of poking around, I discovered that the 3rd parameter is positve, then negative.
is this a valid use so my hook only processes once?
I found several posts here; but none seemed to address the double-calling; some use the 3rd parameter as a structure (I get invalid memory if I try to access the structure elements) others just ignore it.
Thanks
-j
Re: Keyboard hooks; called twice?
Posted: Fri Jun 17, 2011 4:59 pm
by luis
A program stripped to the bare minimum exhibiting some kind of behavior and subsequently a question from you about that behavior would help.

Re: Keyboard hooks; called twice?
Posted: Sat Jun 18, 2011 2:22 am
by jassing
luis wrote:A program stripped to the bare minimum exhibiting some kind of behavior and subsequently a question from you about that behavior would help.

Um, ok
Code: Select all
Procedure.l myKeyboardHook(nCode, wParam, lParam)
What is the 3rd parameter used for? Currently I've noticed that it's positive on the 1st call, negative on the 2nd.
Re: Keyboard hooks; called twice?
Posted: Sat Jun 18, 2011 5:16 am
by MachineCode
How does that single line of code exhibit some kind of behavior with which we can work? We don't know what the third parameter is used for because we can't see the entire procedure, nor the context in which the procedure is called.
Re: Keyboard hooks; called twice?
Posted: Sat Jun 18, 2011 9:16 am
by Trond
In the documentation for SetWindowsHookEx_() (which I guess you used,
but I can only guess, because you didn't tell or show) there is a link to each type of hook procedure, explaining the parameters.
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Re: Keyboard hooks; called twice?
Posted: Sat Jun 18, 2011 4:47 pm
by jassing
You're right; I am sorry -- I thought I pasted both parts.
Here's the call to set the hook.
hhook = SetWindowsHookEx_(#WH_KEYBOARD, @myKeyboardHook(), hInstance, GetCurrentThreadId_())
Thank you for the links; I will read there instead.
Cheers
-j