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. How can I hook Joystick?

How can I hook Joystick?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionsysadmin
3 Posts 2 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.
  • E Offline
    E Offline
    ekklesia
    wrote on last edited by
    #1

    Now trying to hook joystick.but it's not easy to me. below is my source. //------------------------------------------------------------------ // Set Hook //------------------------------------------------------------------ BOOL SetHook( HWND hWnd ) { g_HwndServer = hWnd ; // Set Hook Server if(joySetCapture( g_HwndServer , JOYSTICKID1, 0, FALSE)) { MessageBox(g_HwndServer, "Unable to capture the joystick", NULL, MB_OK); } // set movement threshold //....................... { UINT nThreshold; joyGetThreshold(JOYSTICKID1, &nThreshold); if (nThreshold < 100) { nThreshold = 100; joySetThreshold(JOYSTICKID1, nThreshold); } } g_Hook = SetWindowsHookEx( WH_GETMESSAGE , GetMessageProc, (HINSTANCE)g_Module , 0 ) ; return false ; } //------------------------------------------------------------------ // Remove Hook //------------------------------------------------------------------ BOOL RemoveHook() { joyReleaseCapture(JOYSTICKID1); UnhookWindowsHookEx( g_Hook ) ; return true ; } //-------------------------------------------------------------- // Hook Procedure - Keyboard //-------------------------------------------------------------- LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam) { LPMSG msg=(LPMSG)lParam; if ((nCode >= 0) && PM_REMOVE == wParam && (msg->message == MM_JOY1MOVE { MessageBox( g_HwndServer, "Joistick", NULL, MB_OK); } // We must pass the all messages on to CallNextHookEx. return ::CallNextHookEx( g_Hook , nCode , wParam , lParam ); } the problem is that though i don't move joystick this above code is executed. i hope you help me to solve this problem. God bless you! nice to meet u

    A 1 Reply Last reply
    0
    • E ekklesia

      Now trying to hook joystick.but it's not easy to me. below is my source. //------------------------------------------------------------------ // Set Hook //------------------------------------------------------------------ BOOL SetHook( HWND hWnd ) { g_HwndServer = hWnd ; // Set Hook Server if(joySetCapture( g_HwndServer , JOYSTICKID1, 0, FALSE)) { MessageBox(g_HwndServer, "Unable to capture the joystick", NULL, MB_OK); } // set movement threshold //....................... { UINT nThreshold; joyGetThreshold(JOYSTICKID1, &nThreshold); if (nThreshold < 100) { nThreshold = 100; joySetThreshold(JOYSTICKID1, nThreshold); } } g_Hook = SetWindowsHookEx( WH_GETMESSAGE , GetMessageProc, (HINSTANCE)g_Module , 0 ) ; return false ; } //------------------------------------------------------------------ // Remove Hook //------------------------------------------------------------------ BOOL RemoveHook() { joyReleaseCapture(JOYSTICKID1); UnhookWindowsHookEx( g_Hook ) ; return true ; } //-------------------------------------------------------------- // Hook Procedure - Keyboard //-------------------------------------------------------------- LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam) { LPMSG msg=(LPMSG)lParam; if ((nCode >= 0) && PM_REMOVE == wParam && (msg->message == MM_JOY1MOVE { MessageBox( g_HwndServer, "Joistick", NULL, MB_OK); } // We must pass the all messages on to CallNextHookEx. return ::CallNextHookEx( g_Hook , nCode , wParam , lParam ); } the problem is that though i don't move joystick this above code is executed. i hope you help me to solve this problem. God bless you! nice to meet u

      A Offline
      A Offline
      Alexander M
      wrote on last edited by
      #2

      Why aren't you using DirectInput? Don't try it, just do it! ;-)

      E 1 Reply Last reply
      0
      • A Alexander M

        Why aren't you using DirectInput? Don't try it, just do it! ;-)

        E Offline
        E Offline
        ekklesia
        wrote on last edited by
        #3

        your advice is correct. DirectInput is very good. i don't need to hook joystick it is enough to use directInput. Thank you. God bless you. nice to meet u

        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