Query on WH_KEYBOARD Experts help
-
Sir, THis is my first application with hooks. I amtrying to register WH_KEYBOARD hook for my app so that when ever I tried to make Caps tab on this will set to off. So I placed a gloabl variable of HHOKDATA and a glabal proc -KeyboardProc. I placed these globally in CMainFrm.cpp I registered this hook using using SetWindowsHookEx and called in OnCreate of CMainfrm.cpp. But this is not getting called and let me know what to do so that this hook should call . Should I map the events ???? But hooks will getcalled only before the event is passed to WndProc? Pls correct me if I am wrong. Where I am going wrong?
-
Sir, THis is my first application with hooks. I amtrying to register WH_KEYBOARD hook for my app so that when ever I tried to make Caps tab on this will set to off. So I placed a gloabl variable of HHOKDATA and a glabal proc -KeyboardProc. I placed these globally in CMainFrm.cpp I registered this hook using using SetWindowsHookEx and called in OnCreate of CMainfrm.cpp. But this is not getting called and let me know what to do so that this hook should call . Should I map the events ???? But hooks will getcalled only before the event is passed to WndProc? Pls correct me if I am wrong. Where I am going wrong?
blacktiger007 wrote: I registered this hook using using SetWindowsHookEx and called in OnCreate of CMainfrm.cpp. But this is not getting called and let me know what to do so that this hook should call . What is not being called?
SetWindowsHookEx
or the hook you are trying to install? blacktiger007 wrote: But hooks will getcalled only before the event is passed to WndProc? Hooks are called before the window message is delivered to a message pump. If you are trying to install a global hook, please note the section in the MSDN docs: The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure. Are you installing a global hook? If so, do you really need the global hook? If you are installing a global hook and you really need it, there's this[^] article. -- Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr. Welle: Erdball - F104-G Starfighter -
Sir, THis is my first application with hooks. I amtrying to register WH_KEYBOARD hook for my app so that when ever I tried to make Caps tab on this will set to off. So I placed a gloabl variable of HHOKDATA and a glabal proc -KeyboardProc. I placed these globally in CMainFrm.cpp I registered this hook using using SetWindowsHookEx and called in OnCreate of CMainfrm.cpp. But this is not getting called and let me know what to do so that this hook should call . Should I map the events ???? But hooks will getcalled only before the event is passed to WndProc? Pls correct me if I am wrong. Where I am going wrong?
sir why not use a dll to set the hooks and put the callback function there. The virtual keycodes for capslock and tab are: VK_CAPITAL 14(value hexadecimal) CAPS LOCK key VK_TAB 09(value hexadecimal) TAB key So in your callback function you'll have to monitor whenever these key are pressed and when they are pressed instead of returning 0 (as success) return 1 (as error). And there you are gabby
-
blacktiger007 wrote: I registered this hook using using SetWindowsHookEx and called in OnCreate of CMainfrm.cpp. But this is not getting called and let me know what to do so that this hook should call . What is not being called?
SetWindowsHookEx
or the hook you are trying to install? blacktiger007 wrote: But hooks will getcalled only before the event is passed to WndProc? Hooks are called before the window message is delivered to a message pump. If you are trying to install a global hook, please note the section in the MSDN docs: The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure. Are you installing a global hook? If so, do you really need the global hook? If you are installing a global hook and you really need it, there's this[^] article. -- Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr. Welle: Erdball - F104-G StarfighterI called a global hook and wrote the code in CMainFrm.cpp fie and called SetWindowsHookEx in OnCreate of CMainFrm. I wrote the code KeyboardProc here. When I tried to debug it ,The actual KeyboardProc deined in this file is not geting called. Pls solve this as I will extend this app using DLLs later.
-
sir why not use a dll to set the hooks and put the callback function there. The virtual keycodes for capslock and tab are: VK_CAPITAL 14(value hexadecimal) CAPS LOCK key VK_TAB 09(value hexadecimal) TAB key So in your callback function you'll have to monitor whenever these key are pressed and when they are pressed instead of returning 0 (as success) return 1 (as error). And there you are gabby
Sir, Thx for the response. This is the code for a global hook which I defined in MainFrm.cpp But even without using a dll this should get fired after registering the hook by calling SetWindowsHookEx in OnCreate of CMainFrm Pls correct me if I m wrong . LRESULT CALLBACK KeyboardProc(int code,WPARAM w,LPARAM l) { if (code < 0) return CallNextHookEx(m_hookData,code,w,l); unsigned char state[256]; if( w == VK_CAPITAL) { GetKeyboardState(state); if(state[VK_CAPITAL] == 1) { state[VK_CAPITAL] =0; SetKeyboardState(state); } } return CallNextHookEx(m_hookData,code,w,l); }
-
I called a global hook and wrote the code in CMainFrm.cpp fie and called SetWindowsHookEx in OnCreate of CMainFrm. I wrote the code KeyboardProc here. When I tried to debug it ,The actual KeyboardProc deined in this file is not geting called. Pls solve this as I will extend this app using DLLs later.
I'll recite the MSDN docs again: All global hook functions must be in libraries. Those are the rules. Period. -- Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr. Welle: Erdball - F104-G Starfighter