Example #1
0
f2dInputMouseImpl::f2dInputMouseImpl(f2dInputSysImpl* pSys, HWND Win, const GUID& pGUID, fBool bGlobalFocus)
	: m_pSys(pSys), m_pDev(NULL), m_DefaultListener(pSys), m_pListener(&m_DefaultListener),
	m_TotalOffsetX(0), m_TotalOffsetY(0), m_TotalOffsetZ(0)
{
	IDirectInput8* pDev = pSys->GetHandle();

	memset(m_BtnState, 0, sizeof(m_BtnState));

	HRESULT tHR = pDev->CreateDevice(pGUID, &m_pDev, NULL);
	if(FAILED(tHR))
		throw fcyWin32COMException("f2dInputMouseImpl::f2dInputMouseImpl", "CreateDevice Failed.", tHR);
	
	// 设置协作模式
	fuInt tFlag = DISCL_NONEXCLUSIVE;
	if(bGlobalFocus)
		tFlag |= DISCL_BACKGROUND;
	else
		tFlag |= DISCL_FOREGROUND;
	tHR = m_pDev->SetCooperativeLevel(Win, tFlag);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputMouseImpl::f2dInputMouseImpl", "SetCooperativeLevel Failed.", tHR);
	}

    // 设置数据格式
    tHR = m_pDev->SetDataFormat(&DIDF_Mouse);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputMouseImpl::f2dInputMouseImpl", "SetDataFormat Failed.", tHR);
	}

	// 设置缓冲区
	DIPROPDWORD tBufferProperty;

    tBufferProperty.diph.dwSize = sizeof(DIPROPDWORD);
    tBufferProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    tBufferProperty.diph.dwObj = 0;
    tBufferProperty.diph.dwHow = DIPH_DEVICE;
    tBufferProperty.dwData = BufferSize;

    tHR = m_pDev->SetProperty(DIPROP_BUFFERSIZE, &tBufferProperty.diph);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputMouseImpl::f2dInputMouseImpl", "SetProperty Failed.", tHR);
	}

	// 获得设备
	tHR = m_pDev->Acquire();

	// 注册
	m_pSys->RegisterDevice(this);
}
Example #2
0
BOOL CALLBACK EnumGamePadCallback(const DIDEVICEINSTANCE* pDIDeviceInstance, VOID* pContext)
{
	// Obtain an interface to the enumerated joystick.
	IDirectInput8*		  pDI = DXInput::Get()->mpDI;
	IDirectInputDevice8**   pGamePad = &(DXInput::Get()->mpGamePad);
	if (FAILED(pDI->CreateDevice(pDIDeviceInstance->guidInstance, pGamePad, nullptr))) 
	{
		// Write to log
		Log::Get()->Write(LogType::Warning, "[Input] Failed to create game pad device.");
	}

	return DIENUM_STOP;
}
    /*** IDirectInput8A methods ***/
    HRESULT _stdcall CreateDevice(REFGUID r,IDirectInputDevice8A** device,IUnknown* unused) {
        if(r!=GUID_SysKeyboard&&r!=GUID_SysMouse) { 
			return RealInput->CreateDevice(r,device,unused);
		} else {
            DWORD d;
			IDirectInputDevice8A* RealDevice;
			HRESULT hr;

            if(r==GUID_SysKeyboard) d=kDeviceType_KEYBOARD;
            else d=kDeviceType_MOUSE;
            hr=RealInput->CreateDevice(r,&RealDevice,unused);
            if(hr!=DI_OK) return hr;
            *device=new FakeDirectInputDevice(RealDevice,d);
            return DI_OK;
        }
    }
    ULONG _stdcall Release(void) {
		if(--Refs==0) {
			RealInput->Release();
			delete this;
			return 0;
		} else { return Refs; }
    }
 HRESULT _stdcall ConfigureDevices(LPDICONFIGUREDEVICESCALLBACK a,LPDICONFIGUREDEVICESPARAMSA b,DWORD c,void* d) { return RealInput->ConfigureDevices(a,b,c,d); }
 HRESULT _stdcall EnumDevicesBySemantics(LPCSTR a,LPDIACTIONFORMATA b,LPDIENUMDEVICESBYSEMANTICSCBA c,void* d,DWORD e) { return RealInput->EnumDevicesBySemantics(a,b,c,d,e); }
 HRESULT _stdcall FindDevice(REFGUID a,LPCSTR b,LPGUID c) { return RealInput->FindDevice(a,b,c); }
 HRESULT _stdcall Initialize(HINSTANCE a,DWORD b) { return RealInput->Initialize(a,b); }
 HRESULT _stdcall RunControlPanel(HWND a,DWORD b) { return RealInput->RunControlPanel(a,b); }
 HRESULT _stdcall GetDeviceStatus(REFGUID r) { return RealInput->GetDeviceStatus(r); }
 HRESULT _stdcall EnumDevices(DWORD a,LPDIENUMDEVICESCALLBACKA b,void* c,DWORD d) { return RealInput->EnumDevices(a,b,c,d); }
 /*** IUnknown methods ***/
 HRESULT _stdcall QueryInterface (REFIID riid, LPVOID* ppvObj) { return RealInput->QueryInterface(riid,ppvObj); }
Example #13
0
CDIMouse::CDIMouse( HWND hwnd, IDirectInput8& di8 )
:	mDIMouse( NULL )
{
	HRESULT hRes;
	DWORD   dwCoopFlags;

	dwCoopFlags = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
//	dwCoopFlags = DISCL_EXCLUSIVE | DISCL_FOREGROUND;
	
	// Obtain an interface to the system mouse device.
	hRes = di8.CreateDevice(
		GUID_SysMouse,
		&mDIMouse,
		NULL );
	assert( SUCCEEDED( hRes ) );
	assert( mDIMouse );
	
    
    // Set the data format to "mouse format" - a predefined data format 
    //
    // A data format specifies which controls on a device we
    // are interested in, and how they should be reported.
    //
    // This tells DirectInput that we will be passing a
    // DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState.
	hRes = mDIMouse->SetDataFormat( &c_dfDIMouse );
	assert( SUCCEEDED( hRes ) );
	
	// Set the mouse axis mode to relative
	// See "Interpreting Mouse Axis Data" topic
	DIPROPDWORD diprop;
	diprop.diph.dwSize = sizeof( diprop );
	diprop.diph.dwHeaderSize = sizeof( diprop.diph );
	diprop.diph.dwObj = 0;
	diprop.diph.dwHow = DIPH_DEVICE;
	diprop.dwData = DIPROPAXISMODE_REL;
    hRes = mDIMouse->SetProperty( DIPROP_AXISMODE, &diprop.diph );
	assert( SUCCEEDED( hRes ) );

	
	// Set the cooperativity level to let DirectInput know how
    // this device should interact with the system and with other
    // DirectInput applications.
	hRes = mDIMouse->SetCooperativeLevel( hwnd, dwCoopFlags );
	assert( SUCCEEDED( hRes ) );

	for( int q = 0; q < gDim2ButtonCount; q++ )
	{
		int index = ::gDim2Button[q].dim;
		assert( index >= 0 && index < BUTTON_COUNT );
		
		mButtonByDim[ index ] = ::gDim2Button[q].button;
	}
	
/*	// IMPORTANT STEP TO USE BUFFERED DEVICE DATA!
	//
	// DirectInput uses unbuffered I/O (buffer size = 0) by default.
	// If you want to read buffered data, you need to set a nonzero
	// buffer size.
	//
	// Set the buffer size to DINPUT_BUFFERSIZE (defined above) elements.
	//
	// The buffer size is a DWORD property associated with the device.
	DIPROPDWORD dipdw;

	dipdw.diph.dwSize       = sizeof(DIPROPDWORD);
	dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
	dipdw.diph.dwObj        = 0;
	dipdw.diph.dwHow        = DIPH_DEVICE;
	dipdw.dwData            = SAMPLE_BUFFER_SIZE; // Arbitary buffer size

	if( FAILED( hr = mDirectInput8Keyboard->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) )
		throw EError( "keyboard device buffer size setting failed" );
*/
	// Acquire the newly created device
	mDIMouse->Acquire();
}
Example #14
0
f2dInputJoystickImpl::f2dInputJoystickImpl(f2dInputSysImpl* pSys, HWND Win, const GUID& pGUID, bool bGlobalFocus)
	: m_pSys(pSys), m_pDev(NULL), m_DefaultListener(pSys), m_pListener(&m_DefaultListener),
	m_lXHalf(0), m_lXHalfLen(0), m_lYHalf(0), m_lYHalfLen(0), m_lZHalf(0), m_lZHalfLen(0), 
	m_lRxHalf(0), m_lRxHalfLen(0), m_lRyHalf(0), m_lRyHalfLen(0), m_lRzHalf(0), m_lRzHalfLen(0),
	m_lX(0.f), m_lY(0.f), m_lZ(0.f), m_lRx(0.f), m_lRy(0.f), m_lRz(0.f)
{
	IDirectInput8* pDev = pSys->GetHandle();

	memset(m_ButtonDown, 0, sizeof(m_ButtonDown));
	memset(m_Slider, 0, sizeof(m_Slider));
	memset(m_POV, 0, sizeof(m_POV));

	HRESULT tHR = pDev->CreateDevice(pGUID, &m_pDev, NULL);
	if(FAILED(tHR))
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "CreateDevice Failed.", tHR);
	
	// ÉèÖÃЭ×÷ģʽ
	fuInt tFlag = DISCL_NONEXCLUSIVE;
	if(bGlobalFocus)
		tFlag |= DISCL_BACKGROUND;
	else
		tFlag |= DISCL_FOREGROUND;
	tHR = m_pDev->SetCooperativeLevel(Win, tFlag);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetCooperativeLevel Failed.", tHR);
	}

    // ÉèÖÃÊý¾Ý¸ñʽ
	tHR = m_pDev->SetDataFormat(&DIDF_Joystick);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetDataFormat Failed.", tHR);
	}
	
	// ÉèÖûº³åÇø
	DIPROPDWORD tBufferProperty;

    tBufferProperty.diph.dwSize = sizeof(DIPROPDWORD);
    tBufferProperty.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    tBufferProperty.diph.dwObj = 0;
    tBufferProperty.diph.dwHow = DIPH_DEVICE;
    tBufferProperty.dwData = BufferSize;

    tHR = m_pDev->SetProperty(DIPROP_BUFFERSIZE, &tBufferProperty.diph);
	if(FAILED(tHR))
	{
		FCYSAFEKILL(m_pDev);
		throw fcyWin32COMException("f2dInputJoystickImpl::f2dInputJoystickImpl", "SetProperty Failed.", tHR);
	}

	initStates();

	// »ñµÃÉ豸
	tHR = m_pDev->Acquire();

	// ×¢²á
	m_pSys->RegisterDevice(this);
}