Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Query on WH_KEYBOARD Experts help

Query on WH_KEYBOARD Experts help

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasehelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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?

    J G 2 Replies Last reply
    0
    • L Lost User

      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?

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #2

      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

      U 1 Reply Last reply
      0
      • L Lost User

        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?

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        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

        U 1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          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

          U Offline
          U Offline
          User 1149186
          wrote on last edited by
          #4

          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.

          J 1 Reply Last reply
          0
          • G gamitech

            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

            U Offline
            U Offline
            User 1149186
            wrote on last edited by
            #5

            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); }

            1 Reply Last reply
            0
            • U User 1149186

              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.

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups