Keyboard hooks; called twice?

Windows specific forum
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Keyboard hooks; called twice?

Post 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
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Keyboard hooks; called twice?

Post 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. :wink:
"Have you tried turning it off and on again ?"
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Keyboard hooks; called twice?

Post 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. :wink:
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.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Keyboard hooks; called twice?

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Keyboard hooks; called twice?

Post 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
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Keyboard hooks; called twice?

Post 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
Post Reply