How can I hook Joystick?
-
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
-
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
Why aren't you using DirectInput? Don't try it, just do it! ;-)
-
Why aren't you using DirectInput? Don't try it, just do it! ;-)