Sign in to follow this  
The C modest god

Joystick/Pad (and more)

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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::EnumDevices
BOOL 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 initialization
void 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this