Ejemplo n.º 1
0
int KeyboardInitialize(void) {
	if (lpdid)
		return(1);

	ddrval = IDirectInput7_CreateDeviceEx(lpDI, &GUID_SysKeyboard, &IID_IDirectInputDevice7, (LPVOID*)&lpdid, 0);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error creating keyboard device.");
		return 0;
	}

	ddrval = IDirectInputDevice7_SetCooperativeLevel(lpdid, hAppWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error setting keyboard cooperative level.");
		return 0;
	}

	ddrval = IDirectInputDevice7_SetDataFormat(lpdid, &c_dfDIKeyboard);
	if (ddrval != DI_OK) {
		FCEUD_PrintError("DirectInput: Error setting keyboard data format.");
		return 0;
	}

	ddrval = IDirectInputDevice7_Acquire(lpdid);
	/* Not really a fatal error. */
	//if(ddrval != DI_OK)
	//{
	// FCEUD_PrintError("DirectInput: Error acquiring keyboard.");
	// return 0;
	//}
	return 1;
}
Ejemplo n.º 2
0
Archivo: in_win.c Proyecto: jite/jquake
qbool IN_InitDInput (void) 
{
#if DIRECTINPUT_VERSION	>= 0x0700
    HRESULT hr;
	DIPROPDWORD	dipdw = {
		{
			sizeof(DIPROPDWORD),        // diph.dwSize
			sizeof(DIPROPHEADER),       // diph.dwHeaderSize
			0,                          // diph.dwObj
			DIPH_DEVICE,                // diph.dwHow
		},
		DI_BufSize(),              // dwData
	};
	DIDATAFORMAT qdf = {
		sizeof(DIDATAFORMAT),			// this structure
			sizeof(DIOBJECTDATAFORMAT),		// size of object data format
			DIDF_RELAXIS,					// absolute axis coordinates
			sizeof(MYDATA),					// device data size
			sizeof(rgodf)/sizeof(rgodf[0]),	// number of objects
			rgodf							// and here they are
	};

	if (!hInstDI)
	{
		hInstDI = LoadLibrary("dinput.dll");
		
		if (hInstDI == NULL)
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't load dinput.dll\n");
			return false;
		}
	}

	if (!pDirectInputCreateEx)
	{
		pDirectInputCreateEx = (void *)GetProcAddress(hInstDI,"DirectInputCreateEx");
		if (!pDirectInputCreateEx) 
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't get DI proc addr\n");
			return false;
		}
	}

	// register with DirectInput and get an IDirectInput to play with.
	hr = pDirectInputCreateEx(global_hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput7, (LPVOID *) &g_pdi, NULL);

	if (FAILED(hr))
		return false;

	// obtain an interface to the system mouse device.
	hr = IDirectInput7_CreateDeviceEx(g_pdi, &GUID_SysMouse, &IID_IDirectInputDevice7, (LPVOID *) &g_pMouse, NULL);

	if (FAILED(hr))
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't open DI mouse device\n");
		return false;
	}

	// set the data format to "mouse format".
	hr = IDirectInputDevice7_SetDataFormat(g_pMouse, &qdf);

	if (FAILED(hr))
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't set DI mouse format\n");
		return false;
	}

	// set the cooperativity level.
	hr = IDirectInputDevice7_SetCooperativeLevel(g_pMouse, mainwindow, DISCL_EXCLUSIVE | DISCL_FOREGROUND);

	if (FAILED(hr)) 
	{
		Com_Printf_State(PRINT_FAIL, "Couldn't set DI coop level\n");
		return false;
	}

	// set the buffer size to DI_BufSize() elements.
	// the buffer size is a DWORD property associated with the device
	if (in_di_buffered.integer) 
	{
		hr = IDirectInputDevice7_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
		if (FAILED(hr)) 
		{
			Com_Printf_State(PRINT_FAIL, "Couldn't set DI buffersize\n");
			return false;
		}
	}
	else 
	{
		// no properties for immediate input
	}

	IN_SMouseInit();


	return true;
#else // DIRECTINPUT_VERSION	>= 0x0700
	return false;
#endif // DIRECTINPUT_VERSION	>= 0x0700 else
}
Ejemplo n.º 3
0
bool directinput::SetCoopLevel(LPDIRECTINPUTDEVICE7 device, HWND window, bool allowBackgroundAccess) {
	IDirectInputDevice7_Unacquire(device);
	DWORD flags = DISCL_NONEXCLUSIVE | ((allowBackgroundAccess)? DISCL_BACKGROUND:DISCL_FOREGROUND);
	return (DI_OK == IDirectInputDevice7_SetCooperativeLevel(device, window, flags));
}