Joystick/Pad (and more)

Started by
1 comment, last by Cambo_frog 18 years, 9 months ago
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?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
So how do you detect and recognize a joystick?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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

For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.

This topic is closed to new replies.

Advertisement