Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

Joystick/Pad (and more)

This topic is 4868 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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!