Exemple #1
0
IDirectInputDevice8 *BaseInputDevice::create_device(IDirectInput8 *pDI, GUID guid)
{
    IDirectInputDevice8 *device;
    HRESULT hr;
    
    hr = pDI->CreateDevice(guid, &device, NULL);
    if(FAILED(hr))  return NULL;
    
    hr = device->SetCooperativeLevel(Render::hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
    if(FAILED(hr))
    {
        device->Release();  return NULL;
    }
    
    device->Acquire();
    return device;
}
Exemple #2
0
bool
sge::dinput::device::funcs::acquire(
	IDirectInputDevice8 &_device
)
{
	switch(
		_device.Acquire()
	)
	{
	case S_FALSE:
	case DI_OK:
		return
			true;
	case DIERR_OTHERAPPHASPRIO:
		return
			false;
	default:
		throw sge::input::exception(
			FCPPT_TEXT("Acquire() failed!")
		);
	}
}
Exemple #3
0
Gosu::Input::Input(HWND window)
: pimpl(new Impl)
{
    pimpl->window = window;
    pimpl->mouseFactorX = pimpl->mouseFactorY = 1.0;

    // Create the main input object (only necessary for setup).

    IDirectInput8* inputRaw;
    Impl::check("creating the main DirectInput object",
        ::DirectInput8Create(Win::instance(), DIRECTINPUT_VERSION,
            IID_IDirectInput8, reinterpret_cast<void**>(&inputRaw), 0));
    pimpl->input = Win::shareComPtr(inputRaw);


    // Prepare property struct for setting the amount of data to buffer.

    DIPROPDWORD bufferSize;
    bufferSize.diph.dwSize = sizeof(DIPROPDWORD);
    bufferSize.diph.dwHeaderSize = sizeof(DIPROPHEADER);
    bufferSize.diph.dwHow = DIPH_DEVICE;
    bufferSize.diph.dwObj = 0;
    bufferSize.dwData = Impl::inputBufferSize;


    // Set up the system keyboard.

    IDirectInputDevice8* kbRaw;
    Impl::check("creating the keyboard device object",
        pimpl->input->CreateDevice(GUID_SysKeyboard, &kbRaw, 0));
    pimpl->keyboard = Win::shareComPtr(kbRaw);

    Impl::check("setting the keyboard's data format",
        kbRaw->SetDataFormat(&c_dfDIKeyboard));
    Impl::check("setting the keyboard's cooperative level",
        kbRaw->SetCooperativeLevel(window,
            DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
    Impl::check("setting the keyboard's buffer size",
        kbRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));

    kbRaw->Acquire();

    
    // Set up the system mouse.

    IDirectInputDevice8* mouseRaw;
    Impl::check("creating the mouse device object",
        pimpl->input->CreateDevice(GUID_SysMouse, &mouseRaw, 0));
    pimpl->mouse = Win::shareComPtr(mouseRaw);

    Impl::check("setting the mouse's data format",
        mouseRaw->SetDataFormat(&c_dfDIMouse));
    Impl::check("setting the mouse's cooperative level",
        mouseRaw->SetCooperativeLevel(window,
            DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
    Impl::check("setting the mouse's buffer size",
        mouseRaw->SetProperty(DIPROP_BUFFERSIZE, &bufferSize.diph));

    mouseRaw->Acquire();

    pimpl->swapMouse = ::GetSystemMetrics(SM_SWAPBUTTON) != 0;


    // Set up all gamepads.

    pimpl->input->EnumDevices(DI8DEVCLASS_GAMECTRL, Impl::gamepadCallback,
        pimpl.get(), DIEDFL_ATTACHEDONLY);


    // Get into a usable default state.

	pimpl->mouseX = pimpl->mouseY = 0;
    pimpl->updateMousePos();
    buttons.assign(false);
}
 HRESULT _stdcall Acquire(void) { return RealDevice->Acquire(); }