Joystick/Pad (and more)
In DIDEVICEINSTANCE there is the dwDevType.
The main type in the LSByte cannot be a combination of several types?
Such as DI8DEVTYPE_JOYSTICK | DI8DEVTYPE_GAMEPAD?
What sort of a controller is DI8DEVTYPE_1STPERSON?
Quote:Original post by The C modest god
So how do you detect and recognize a joystick?
You need to create an IDirectInput8 interface and call its EnumDevices method.
Here is a code snippet.
LPDIRECTINPUT8 g_pDI = NULL; LPDIRECTINPUTDEVICE8 g_pJoystick = NULL;// callback function for IDirectInput8::EnumDevicesBOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance,VOID* pContext ){ HRESULT hr; // Obtain an interface to the enumerated joystick. hr = g_pDI->CreateDevice( pdidInstance->guidInstance, &g_pJoystick, NULL ); // If it failed, then we can't use this joystick. (Maybe the user unplugged // it while we were in the middle of enumerating it.) if( FAILED(hr) ) return DIENUM_CONTINUE; // Stop enumeration. Note: we're just taking the first joystick we get. You // could store all the enumerated joysticks and let the user pick. return DIENUM_STOP;}// direct input initializationvoid InitDirectInput(){ HRESULT hr; // Create the IDirectInput8 interface V( DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&g_pDI, NULL ) ); // Look for a simple joystick V( g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY ) ); if ( g_pJoystick == NULL ) return; // initialize the joystick here (app specific). // do other direct input inititialization here.}
HTH,
Cambo_frog
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement