Sign in to follow this  

Joystick/Pad (and more)

This topic is 4532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

This topic is 4532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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