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. Other Discussions
  3. Article Writing
  4. system wide keyboard and mouse hooks

system wide keyboard and mouse hooks

Scheduled Pinned Locked Moved Article Writing
4 Posts 3 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    subject says it all

    U 1 Reply Last reply
    0
    • A Anonymous

      subject says it all

      U Offline
      U Offline
      User 1052
      wrote on last edited by
      #2

      Somehting like this.... In your header file static LRESULT CALLBACK KeyboardHook (int nCode, WORD wParam, DWORD lParam ); static LRESULT CALLBACK MouseHook(int nCode, WORD wParam, DWORD lParam); In your source file LRESULT CALLBACK CClientDlg::KeyboardHook (int nCode, WORD wParam, DWORD lParam ) { if ( nCode >= 0 ) { // WHAT YOU WANT IT TO DO } return (int)CallNextHookEx(hHookKB, nCode, wParam, lParam); } LRESULT CALLBACK CClientDlg::MouseHook (int nCode, WORD wParam, DWORD lParam ) { mousecnt++; if ( nCode >= 0 ) { // WHAT DO YOU WANT IT TO DO } return (int)CallNextHookEx(hHookM, nCode, wParam, lParam); } In your initdialog or constructor hHookKB= (HHOOK)SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardHook, 0,GetCurrentThreadId()); hHookM= (HHOOK)SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHook, 0,GetCurrentThreadId());

      W 1 Reply Last reply
      0
      • U User 1052

        Somehting like this.... In your header file static LRESULT CALLBACK KeyboardHook (int nCode, WORD wParam, DWORD lParam ); static LRESULT CALLBACK MouseHook(int nCode, WORD wParam, DWORD lParam); In your source file LRESULT CALLBACK CClientDlg::KeyboardHook (int nCode, WORD wParam, DWORD lParam ) { if ( nCode >= 0 ) { // WHAT YOU WANT IT TO DO } return (int)CallNextHookEx(hHookKB, nCode, wParam, lParam); } LRESULT CALLBACK CClientDlg::MouseHook (int nCode, WORD wParam, DWORD lParam ) { mousecnt++; if ( nCode >= 0 ) { // WHAT DO YOU WANT IT TO DO } return (int)CallNextHookEx(hHookM, nCode, wParam, lParam); } In your initdialog or constructor hHookKB= (HHOOK)SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardHook, 0,GetCurrentThreadId()); hHookM= (HHOOK)SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHook, 0,GetCurrentThreadId());

        W Offline
        W Offline
        wwwaaattt
        wrote on last edited by
        #3

        This works for dll's? Which I presume I will need to put this in to get the system wide hook?

        U 1 Reply Last reply
        0
        • W wwwaaattt

          This works for dll's? Which I presume I will need to put this in to get the system wide hook?

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

          Sorry... should have specified.. to make it system wide... make the 4th parameter of SetWindowsHookEx 0 (zero), instead of GetCurrentThreadID

          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