Jump to content
  • Advertisement
Sign in to follow this  
akira32

Two Joystick and DirectInput

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

I want to write a game program can support two joystick(USB head) Now I success to control player one's joystick. But how to I control player two's joystick. What I should set DirectInput to support two joystick? Do any webs have any sample or book mentioned it? My Source Code as below: case JOYSTICK: if(FAILED(m_Input->GetDirectInputCOM()->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticks, this, DIEDFL_ATTACHEDONLY))) return FALSE; if(m_pDIDevice == NULL) return FALSE; DataFormat = (DIDATAFORMAT*)&c_dfDIJoystick; break; // Set the windowed usage m_Windowed = Windowed; // Set the data format of keyboard if(FAILED(m_pDIDevice->SetDataFormat(DataFormat))) return FALSE; // Set the cooperative level - Foreground & Nonexclusive if(FAILED(m_pDIDevice->SetCooperativeLevel(m_Input->GethWnd(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) return FALSE; // Set the special properties if it's a joystick if(Type == JOYSTICK) { // Set the special properties of the joystick - range DIprg.diph.dwSize = sizeof(DIPROPRANGE); DIprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIprg.diph.dwHow = DIPH_BYOFFSET; //DIprg.diph.dwHow = DIPH_BYID; DIprg.lMin = -1024; DIprg.lMax = +1024; // Set X range DIprg.diph.dwObj = DIJOFS_X; if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph))) return FALSE; // Set Y rangine DIprg.diph.dwObj = DIJOFS_Y; if(FAILED(m_pDIDevice->SetProperty(DIPROP_RANGE, &DIprg.diph))) return FALSE; // Set the special properties of the joystick - deadzone 12% DIpdw.diph.dwSize = sizeof(DIPROPDWORD); DIpdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); DIpdw.diph.dwHow = DIPH_BYOFFSET; DIpdw.dwData = 128; // Set X deadzone DIpdw.diph.dwObj = DIJOFS_X; if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph))) return FALSE; // Set Y deadzone DIpdw.diph.dwObj = DIJOFS_Y; if(FAILED(m_pDIDevice->SetProperty(DIPROP_DEADZONE, &DIpdw.diph))) return FALSE;

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!