BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE* instance, VOID* context) { HRESULT hr; //SLOW!!! if (IsXInputDevice(&instance->guidProduct)) return DIENUM_CONTINUE; // Obtain an interface to the enumerated joystick. hr = m_directInput->CreateDevice(instance->guidInstance, &joystick[wiDirectInput::connectedJoys], 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. wiDirectInput::connectedJoys++; if (wiDirectInput::connectedJoys<2) return DIENUM_CONTINUE; else return DIENUM_STOP; }
BOOL CALLBACK EnumPeripheralsCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { if (GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_GAMEPAD || GET_DIDEVICE_TYPE(lpddi->dwDevType) == DI8DEVTYPE_JOYSTICK) { #ifdef HAVE_XINPUT if (IsXInputDevice(&lpddi->guidProduct)) { dev_list[num_devices].lpDIDevice = NULL; dev_list[num_devices].is_xinput_device = TRUE; dev_list[num_devices].user_index=((int *)pvRef)[0]; ((int *)pvRef)[0]++; num_devices++; } else #endif { dev_list[num_devices].is_xinput_device = FALSE; if (SUCCEEDED(IDirectInput8_CreateDevice(lpDI8, &lpddi->guidInstance, &dev_list[num_devices].lpDIDevice, NULL) )) num_devices++; } } return DIENUM_CONTINUE; }
//----------------------------------------------------------------------------- // Name: EnumJoysticksCallback() // Desc: Called once for each enumerated Joystick. If we find one, create a // device interface on it so we can play with it. //----------------------------------------------------------------------------- BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { DI_ENUM_CONTEXT* pEnumContext = ( DI_ENUM_CONTEXT* )pContext; HRESULT hr; if( g_bFilterOutXinputDevices && IsXInputDevice( &pdidInstance->guidProduct ) ) return DIENUM_CONTINUE; // Skip anything other than the perferred Joystick device as defined by the control panel. // Instead you could store all the enumerated Joysticks and let the user pick. if( pEnumContext->bPreferredJoyCfgValid && !IsEqualGUID( pdidInstance->guidInstance, pEnumContext->pPreferredJoyCfg->guidInstance ) ) return DIENUM_CONTINUE; // 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; }
//=============================================== //ジョイスティックの列挙 //=============================================== //[input] // pdidInstance: // pContext: //[return] // //=============================================== BOOL CALLBACK CInput::EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, void *pContext) { DI_ENUM_CONTEXT *pEnumContext = (DI_ENUM_CONTEXT*)pContext; HRESULT hr; if(m_IsFilterXInputDevice && IsXInputDevice(&pdidInstance->guidProduct) ) { return DIENUM_CONTINUE; } if(pEnumContext->IsPreferredJoyCfg && !IsEqualGUID(pdidInstance->guidInstance, pEnumContext->pPrefrredJoyCfg->guidInstance) ) { return DIENUM_CONTINUE; } /*デバイスの生成*/ hr = m_pDirectInput->CreateDevice(pdidInstance->guidInstance, &m_pJoystickData[m_JoystickCount].pDevice, NULL); if(SUCCEEDED(hr) ) { return (++m_JoystickCount == m_JoystickMax) ? (DIENUM_STOP) : (DIENUM_CONTINUE); } return DIENUM_STOP; }
void CDirectInput::CreateDevices(void) { int i; CDirectInputDetail* psJoystickDetail; HRESULT hResult; for (i = 0; i < masDIJoystickDetail.NumElements(); i++) { psJoystickDetail = masDIJoystickDetail.Get(i); if (!IsXInputDevice(psJoystickDetail)) { psJoystickDetail->bXInput = FALSE; hResult = mpDInput->CreateDevice(psJoystickDetail->guidInstance, &psJoystickDetail->lpDIDevice, NULL); psJoystickDetail->lpDIDevice->SetDataFormat(&c_dfDIJoystick2); if (mpcWinInput->mbExclusive) { hResult = psJoystickDetail->lpDIDevice->SetCooperativeLevel(mpcWinInput->mhWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); } else { hResult = psJoystickDetail->lpDIDevice->SetCooperativeLevel(mpcWinInput->mhWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); } psJoystickDetail->lpDIDevice->Acquire(); } else { psJoystickDetail->bXInput = TRUE; psJoystickDetail->lpDIDevice = NULL; } } }
DinputDevice::DinputDevice() { pJoystick = NULL; pDI = NULL; memset(lastButtons_, 0, sizeof(lastButtons_)); memset(lastPOV_, 0, sizeof(lastPOV_)); last_lX_ = 0; last_lY_ = 0; last_lZ_ = 0; last_lRx_ = 0; last_lRy_ = 0; last_lRz_ = 0; if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL))) return; if(FAILED(pDI->CreateDevice(GUID_Joystick, &pJoystick, NULL ))) { pDI->Release(); pDI = NULL; return; } if(FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) { pJoystick->Release(); pJoystick = NULL; return; } // Ignore if device supports XInput DIDEVICEINSTANCE dinfo = {0}; pJoystick->GetDeviceInfo(&dinfo); if (IsXInputDevice(&dinfo.guidProduct)) { pDI->Release(); pDI = NULL; pJoystick->Release(); pJoystick = NULL; } DIPROPRANGE diprg; diprg.diph.dwSize = sizeof(DIPROPRANGE); diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); diprg.diph.dwHow = DIPH_DEVICE; diprg.diph.dwObj = 0; diprg.lMin = -10000; diprg.lMax = 10000; analog = FAILED(pJoystick->SetProperty(DIPROP_RANGE, &diprg.diph)) ? false : true; // Other devices suffer if the deadzone is not set. // TODO: The dead zone will be made configurable in the Control dialog. DIPROPDWORD dipw; dipw.diph.dwSize = sizeof(DIPROPDWORD); dipw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipw.diph.dwHow = DIPH_DEVICE; dipw.diph.dwObj = 0; // dwData 1000 is deadzone(0% - 10%) dipw.dwData = 1000; analog |= FAILED(pJoystick->SetProperty(DIPROP_DEADZONE, &dipw.diph)) ? false : true; }
//----------------------------------------------------------------------------- // Name: Enumg_pJoysticksCallback() // Desc: Called once for each enumerated g_pJoystick. If we find one, create a // device interface on it so we can play with it. //----------------------------------------------------------------------------- BOOL CALLBACK Enumg_pJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext ) { DI_ENUM_CONTEXT* pEnumContext = ( DI_ENUM_CONTEXT* )pContext; HRESULT hr; if( g_bFilterOutXinputDevices && IsXInputDevice( &pdidInstance->guidProduct ) ) return DIENUM_CONTINUE; // Skip anything other than the perferred g_pJoystick device as defined by the control panel. // Instead you could store all the enumerated g_pJoysticks and let the user pick. if( pEnumContext->bPreferredJoyCfgValid && !IsEqualGUID( pdidInstance->guidInstance, pEnumContext->pPreferredJoyCfg->guidInstance ) ) return DIENUM_CONTINUE; // Obtain an interface to the enumerated g_pJoystick. hr = g_pDI->CreateDevice( pdidInstance->guidInstance, &g_pJoystick, NULL ); // If it failed, then we can't use this g_pJoystick. (Maybe the user unplugged // it while we were in the middle of enumerating it.) if( VP_FAILED( hr ) ) return DIENUM_CONTINUE; // Stop enumeration. Note: we're just taking the first g_pJoystick we get. You // could store all the enumerated g_pJoysticks and let the user pick. if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_127F&PID_E018") )==0) { JoystickType=GAMEPAD_RADIO_GP; printf("Using gamepad settings for an Icarus Gamepad.\n"); } else if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_046D&PID_C21A") )==0) { JoystickType=GAMEPAD_LOGITECH_PRECISION; printf("Using gamepad settings for a Logitech Precision gamepad.\n"); } else if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_054C&PID_0268") )==0) { JoystickType=GAMEPAD_PLAYSTATION3; printf("Using gamepad settings for a Playstation3 gamepad.\n"); } else if ( wcscmp( (const wchar_t*)&pEnumContext->pPreferredJoyCfg->wszType , TEXT("VID_06A3&PID_0836") )==0) { JoystickType=JOYSTICK_CYBORG_X; printf("Using gamepad settings for a CyborgX joystick.\n"); } else { JoystickType=GAMEPAD_UNKNOWN; printf("Unknown gamepad. Controls are disabled.\n"); } return DIENUM_STOP; }
BOOL FAR PASCAL DInputEnumDevicesCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef) { std::vector<DIDEVICEINSTANCE> *list = (std::vector<DIDEVICEINSTANCE> *)pvRef; if (IsXInputDevice(&lpddi->guidProduct)) { Log(Debug, "XInput device found: %S", lpddi->tszProductName); } else { Log(Debug, "Direct input device found: %S", lpddi->tszProductName); list->push_back(*lpddi); } return DIENUM_CONTINUE; }
// Called by the DirectInput enumerator for each attached DI device. We use it to make a list of devices. // EnumMakeDeviceList has been rewritten. --rabid BOOL CALLBACK EnumMakeDeviceList( LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef ) { if( IsXInputDevice( &lpddi->guidProduct ) ) // Check if is XInput device --tecnicors return DIENUM_CONTINUE; if (IsEqualGUID(g_sysMouse.guidInstance, lpddi->guidInstance)) return DIENUM_CONTINUE; for (int i = 0; i < g_nDevices; i++) if (IsEqualGUID(g_devList[i].guidInstance, lpddi->guidInstance)) return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; if (g_nDevices < ARRAYSIZE(g_devList)) // our buffer isn't full yet and the device doesn't already exist in our table { lstrcpyn( g_devList[g_nDevices].szProductName, lpddi->tszProductName, MAX_PATH ); g_devList[g_nDevices].dwDevType = lpddi->dwDevType; g_devList[g_nDevices].guidInstance = lpddi->guidInstance; g_devList[g_nDevices].bProductCounter = 0; // counting similar devices for( int i = 0; i < g_nDevices; ++i ) { if( !lstrcmp( lpddi->tszProductName, g_devList[i].szProductName )) { if( g_devList[g_nDevices].bProductCounter == 0 ) { g_devList[g_nDevices].bProductCounter = 2; if( g_devList[i].bProductCounter == 0 ) g_devList[i].bProductCounter = 1; } else g_devList[g_nDevices].bProductCounter++; // give em instance numbers } } if( !lstrcmp( lpddi->tszProductName, TEXT( STRING_ADAPTOID ))) g_devList[g_nDevices].bEffType = RUMBLE_DIRECT; else g_devList[g_nDevices].bEffType = RUMBLE_NONE; if ( GetInputDevice(g_strEmuInfo.hMainWindow, g_devList[g_nDevices].didHandle, lpddi->guidInstance, lpddi->dwDevType, DIB_DEVICE) ) { g_devList[g_nDevices].didHandle->EnumEffects( EnumGetEffectTypes, &g_devList[g_nDevices].bEffType, DIEFT_ALL ); g_nDevices++; } else ZeroMemory(&g_devList[g_nDevices], sizeof(DEVICE)); } return ( g_nDevices < ARRAYSIZE(g_devList) ) ? DIENUM_CONTINUE : DIENUM_STOP; }
DinputDevice::DinputDevice() { pJoystick = NULL; pDI = NULL; if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL))) return; if(FAILED(pDI->CreateDevice(GUID_Joystick, &pJoystick, NULL ))) { pDI->Release(); pDI = NULL; return; } if(FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) { pJoystick->Release(); pJoystick = NULL; return; } // ignore if device suppert XInput DIDEVICEINSTANCE dinfo = {0}; pJoystick->GetDeviceInfo(&dinfo); if (IsXInputDevice(&dinfo.guidProduct)) { pDI->Release(); pDI = NULL; pJoystick->Release(); pJoystick = NULL; } DIPROPRANGE diprg; diprg.diph.dwSize = sizeof(DIPROPRANGE); diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER); diprg.diph.dwHow = DIPH_DEVICE; diprg.diph.dwObj = 0; diprg.lMin = -10000; diprg.lMax = 10000; analog = FAILED(pJoystick->SetProperty(DIPROP_RANGE, &diprg.diph))?false:true; }