当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTINPUTDEVICE::Acquire方法代码示例

本文整理汇总了C++中LPDIRECTINPUTDEVICE::Acquire方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE::Acquire方法的具体用法?C++ LPDIRECTINPUTDEVICE::Acquire怎么用?C++ LPDIRECTINPUTDEVICE::Acquire使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECTINPUTDEVICE的用法示例。


在下文中一共展示了LPDIRECTINPUTDEVICE::Acquire方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PisteInput_Alusta_Mouse

bool PisteInput_Alusta_Mouse()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysMouse, &PI_lpdimouse, NULL))) {
		PisteLog_Kirjoita("[Warning] Piste Input: No mouse available! \n");
		PI_mouse_available = false;
	}

	if (PI_mouse_available)
	{
		if (FAILED(PI_lpdimouse->SetCooperativeLevel(PI_main_window_handle,
			DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set cooperative level failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->SetDataFormat(&c_dfDIMouse))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set data format failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->Acquire())) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Acquire failed! \n");
			PI_mouse_available = false;
		}
	}

	return PI_mouse_available;
}
开发者ID:stt,项目名称:pk2,代码行数:29,代码来源:PisteInput.cpp

示例2: initDirectInput

bool DXGame::initDirectInput(HINSTANCE hInstance){
	dprintf(("Entered initDirectInput\n"));
	if(FAILED(DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &lpDirectInput, NULL))){
		dprintf(("*****COULD NOT CREATE DIRECT INPUT OBJECT*****\n"));
	}
	if(FAILED(lpDirectInput->CreateDevice(GUID_SysKeyboard, &lpKeyboard, NULL))){
		dprintf(("*****COULD NOT CREATE KEYBOARD*****\n"));
	}

	// set cooperation level
	if (lpKeyboard->SetCooperativeLevel(hwnd, 
		DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK){
		dprintf(("COULD NOT SetCooperative Level\n"));
		return false;
	}
		

	// set data format
	if (lpKeyboard->SetDataFormat(&c_dfDIKeyboard)!=DI_OK){
		dprintf(("COULD NOT Set Data Format\n"));
		return false;
	}
	

	// acquire the keyboard
	if (lpKeyboard->Acquire()!=DI_OK){
		dprintf(("COULD NOT Acquire the keyboard\n"));
		return false;
	}
	
	dprintf(("Leaving the DirectInput\n"));

	return true;
}
开发者ID:brettatoms,项目名称:robopanic,代码行数:34,代码来源:DXGame.cpp

示例3: PisteInput_Alusta_Keyboard

bool PisteInput_Alusta_Keyboard()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysKeyboard, &PI_lpdikey, NULL))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Create Device failed! \n");
		return false;
	}
	
	if (FAILED(PI_lpdikey->SetCooperativeLevel(PI_main_window_handle, 
		DISCL_BACKGROUND | DISCL_NONEXCLUSIVE /* | DISCL_FOREGROUND*/))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set cooperative level failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->SetDataFormat(&c_dfDIKeyboard))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set data format failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->Acquire())) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Acquire failed! \n");
		return false;
	}

	return true;
}
开发者ID:stt,项目名称:pk2,代码行数:26,代码来源:PisteInput.cpp

示例4: mouse_eval_deltas_di

void mouse_eval_deltas_di()
{
	int repeat = 1;
	HRESULT hr = 0;
	DIMOUSESTATE mouse_state;

	Mouse_dx = Mouse_dy = Mouse_dz = 0;
	if (!Di_mouse_inited)
		return;

	repeat = 1;
	memset(&mouse_state, 0, sizeof(mouse_state));
	while (repeat) {
		repeat = 0;

		hr = Di_mouse->GetDeviceState(sizeof(mouse_state), &mouse_state);
		if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
			// DirectInput is telling us that the input stream has
			// been interrupted.  We aren't tracking any state
			// between polls, so we don't have any special reset
			// that needs to be done.  We just re-acquire and
			// try again.
			Sleep(500);		// Pause a half second...
			hr = Di_mouse->Acquire();
			if (SUCCEEDED(hr))
				repeat = 1;
		}
	}

	if (SUCCEEDED(hr)) {
		Mouse_dx = (int) mouse_state.lX;
		Mouse_dy = (int) mouse_state.lY;
		Mouse_dz = (int) mouse_state.lZ;

	} else {
		Mouse_dx = Mouse_dy = Mouse_dz = 0;
	}

	Mouse_x += Mouse_dx;
	Mouse_y += Mouse_dy;

	if (Mouse_x < 0)
		Mouse_x = 0;

	if (Mouse_y < 0)
		Mouse_y = 0;

	if (Mouse_x >= gr_screen.max_w)
   		Mouse_x = gr_screen.max_w - 1;

	if (Mouse_y >= gr_screen.max_h)
  		Mouse_y = gr_screen.max_h - 1;

	// keep the mouse inside our window so we don't switch applications or anything (debug bug people reported?)
	// JH: Dang!  This makes the mouse readings in DirectInput act screwy!
//	mouse_force_pos(gr_screen.max_w / 2, gr_screen.max_h / 2);
}
开发者ID:chief1983,项目名称:Imperial-Alliance,代码行数:57,代码来源:MOUSE.CPP

示例5: InitialiseDirectMouse

BOOL InitialiseDirectMouse()

{
    GUID    guid = GUID_SysMouse;
	HRESULT hres;

	//MouseButton = 0;
    
    // Obtain an interface to the system mouse device.
    hres = lpdi->CreateDevice(guid, &lpdiMouse, NULL);
	if (hres != DI_OK) return FALSE;

    // Set the data format to "mouse format".
    hres = lpdiMouse->SetDataFormat(&c_dfDIMouse);
    if (hres != DI_OK) return FALSE;
	
    //  Set the cooperativity level.

    #if debug
	// This level should allow the debugger to actually work
	// not to mention drop 'n' drag in sub-window mode
    hres = lpdiMouse->SetCooperativeLevel(hWndMain,
                       DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
	#else
	// this level is the most likely to work across
	// multiple mouse drivers
    hres = lpdiMouse->SetCooperativeLevel(hWndMain,
                       DISCL_EXCLUSIVE | DISCL_FOREGROUND);
	#endif
    if (hres != DI_OK) return FALSE;

    //  Set the buffer size for reading the mouse to
	//  DMouse_BufferSize elements
    //  mouse-type should be relative by default, so there
	//  is no need to change axis mode.
    DIPROPDWORD dipdw =
    {
        {
            sizeof(DIPROPDWORD),        // diph.dwSize
            sizeof(DIPROPHEADER),       // diph.dwHeaderSize
            0,                          // diph.dwObj
            DIPH_DEVICE,                // diph.dwHow
        },
        DMouse_BufferSize,              // dwData
    };

    hres = lpdiMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);

    if (hres != DI_OK) return FALSE;

    // try to acquire the mouse
    hres = lpdiMouse->Acquire();
	
	return TRUE;
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:55,代码来源:Di_func.cpp

示例6: Purge

void Input::Purge ()
{
    // Purge queued keyboard items
    if (pdiKeyboard && SUCCEEDED(pdiKeyboard->Acquire()))
    {
        DWORD dwItems = ULONG_MAX;
        if (SUCCEEDED(pdiKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), NULL, &dwItems, 0)) && dwItems)
            TRACE("%lu keyboard items purged\n", dwItems);
    }

    Keyboard::Purge();
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:12,代码来源:Input.cpp

示例7: PisteInput_Hae_Nappaimet

bool PisteInput_Hae_Nappaimet()
{
	HRESULT result;
	bool ok = true;
	
	while (result = PI_lpdikey->GetDeviceState(sizeof(PI_keyboard_state),
		   (LPVOID) PI_keyboard_state) == DIERR_INPUTLOST)
	{
		if (FAILED(result = PI_lpdikey->Acquire()))
		{
			PisteLog_Kirjoita("[Warning] Piste Input: Lost control of keyboard! \n");
			ok = false;
		}
	}
	
	return ok;
}
开发者ID:stt,项目名称:pk2,代码行数:17,代码来源:PisteInput.cpp

示例8: ReadKeyboard

void ReadKeyboard ()
{
    if (pdiKeyboard && SUCCEEDED(pdiKeyboard->Acquire()))
    {
        DIDEVICEOBJECTDATA abEvents[EVENT_BUFFER_SIZE];
        DWORD dwItems = EVENT_BUFFER_SIZE;

        if (SUCCEEDED(pdiKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), abEvents, &dwItems, 0)))
        {
            for (DWORD i = 0 ; i < dwItems ; i++)
            {
                int nScanCode = abEvents[i].dwOfs;
                bool fPressed = !!(abEvents[i].dwData & 0x80);

                Keyboard::SetKey(nScanCode, fPressed);
                TRACE("%d %s\n", nScanCode, fPressed ? "pressed" : "released");
            }
        }
    }
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:20,代码来源:Input.cpp

示例9: GameLoopBody

inline void GameLoopBody(HWND wnd)
{
		if(pKeyboard->GetDeviceState(KEYBUFCOUNT * sizeof(keyboardBuffer[0]), (LPVOID) &keyboardBuffer) == DIERR_INPUTLOST)
		{
			if(pKeyboard->Acquire() == DI_OK)
				pKeyboard->GetDeviceState(KEYBUFCOUNT * sizeof(keyboardBuffer[0]), (LPVOID) &keyboardBuffer);
		}

		if(rotationAngle <= 0.0f)
			rotationAngle = 360.0f;
		else
			rotationAngle -= 0.1f;

		// Get keyboard input
		if(KEYDOWN(keyboardBuffer, DIK_LEFT) || KEYDOWN(keyboardBuffer, DIK_A))
			keyPressed = 1;
		if(KEYDOWN(keyboardBuffer, DIK_RIGHT) || KEYDOWN(keyboardBuffer, DIK_D))
			keyPressed = 2;
		if(KEYDOWN(keyboardBuffer, DIK_UP) || KEYDOWN(keyboardBuffer, DIK_W))
			keyPressed = 3;
		if(KEYDOWN(keyboardBuffer, DIK_DOWN) || KEYDOWN(keyboardBuffer, DIK_S))
			keyPressed = 4;

		if(keyPressed == 1)
		{
			if(SphereObjectCoords[0].xcoord <= X_MOTION_LIMIT_LOWER)
				SphereObjectCoords[0].xcoord = X_MOTION_LIMIT_LOWER;
			else
				SphereObjectCoords[0].xcoord -= MOVE_RATE;

			bLineUpOnLongitudeUp = false;
			bLineUpOnLongitudeDown = false;
			bLineUpOnLatitudeR = false;
			bLineUpOnLatitudeL = true;					
		}


		if(keyPressed == 2)
		{	
			if(SphereObjectCoords[0].xcoord >= X_MOTION_LIMIT_UPPER)
				SphereObjectCoords[0].xcoord = X_MOTION_LIMIT_UPPER;
			else
				SphereObjectCoords[0].xcoord += MOVE_RATE;

			bLineUpOnLongitudeUp = false;
			bLineUpOnLongitudeDown = false;
			bLineUpOnLatitudeL = false;
			bLineUpOnLatitudeR = true;
		}	

		if(keyPressed == 3)
		{	
			if(SphereObjectCoords[0].zcoord <= Z_MOTION_LIMIT_UPPER)
				SphereObjectCoords[0].zcoord = Z_MOTION_LIMIT_UPPER;
			else
				SphereObjectCoords[0].zcoord -= MOVE_RATE;
				
			bLineUpOnLongitudeUp = false;
			bLineUpOnLongitudeDown = true;
			bLineUpOnLatitudeR = false;
			bLineUpOnLatitudeL = false;
		}	

		if(keyPressed == 4)
		{
			if(SphereObjectCoords[0].zcoord >= Z_MOTION_LIMIT_LOWER)
				SphereObjectCoords[0].zcoord = Z_MOTION_LIMIT_LOWER;
			else
				SphereObjectCoords[0].zcoord += MOVE_RATE;
				
			bLineUpOnLongitudeUp = true;
			bLineUpOnLongitudeDown = false;
			bLineUpOnLatitudeR = false;
			bLineUpOnLatitudeL = false;
		}

	// Render game/model view.
	switch(iFeatureIsInitialised)
	{
		case 0:
			DisplayMenu(currentMenu, windowed);
			currentMenuOption = FindMenuRegionClicked(currentMenu, g_x_region, g_y_region, windowed);
			ZeroMouseCoords(&g_x_region, &g_y_region);
			SendMenuOptionToMessageQueue(wnd, g_wParam, g_lParam, (int &) currentMenu, currentMenuOption);
			break;
		case 1:
			dik_StandardSphereChain();
			break;
		case 2:
			dik_SphereChainWithSupremeBlast();
			break;
		case 3:
			dik_SphereChainWithRebirth();
			break;
		case 4:
			dik_SphereChainWithSupremeBlastAndRebirth();
			break;
		case 5:
			dik_SphereChainWithInvisibility();
			break;
//.........这里部分代码省略.........
开发者ID:ButchDean,项目名称:AntiVirusGame2,代码行数:101,代码来源:AntiVirusGame.cpp

示例10: DirectReadKeyboard

void DirectReadKeyboard(void)
{
    // Local array for map of all 256 characters on
	// keyboard
	BYTE DiKeybd[256];
	HRESULT hRes;

    // Get keyboard state
    hRes = lpdiKeyboard->GetDeviceState(sizeof(DiKeybd), DiKeybd);
	if (hRes != DI_OK)
      {
	   if (hRes == DIERR_INPUTLOST)
	     {
	      // keyboard control lost; try to reacquire
	      DIKeyboardOkay = FALSE;
	      hRes = lpdiKeyboard->Acquire();
	      if (hRes == DI_OK)
		    DIKeyboardOkay = TRUE;
		 }
      }

    // Check for error values on routine exit
	if (hRes != DI_OK)
	  {
       // failed to read the keyboard
	   #if debug
       ReleaseDirect3D();
	   exit(0x999774);
	   #else
       return;
	   #endif
	  }

	// Take a copy of last frame's inputs:
	memcpy((void*)LastFramesKeyboardInput, (void*)KeyboardInput, MAX_NUMBER_OF_INPUT_KEYS);
	LastGotAnyKey=GotAnyKey;

    // Zero current inputs (i.e. set all keys to FALSE,
	// or not pressed)
    memset((void*)KeyboardInput, FALSE, MAX_NUMBER_OF_INPUT_KEYS);
	GotAnyKey = FALSE;

	#if 1
	{
		int c;
		
		for (c='a'; c<='z'; c++)
		{
			if (IngameKeyboardInput[c])
			{
				KeyboardInput[KEY_A + c - 'a'] = TRUE;
				GotAnyKey = TRUE;
			}	  
		}
		if (IngameKeyboardInput[246])
		{
			KeyboardInput[KEY_O_UMLAUT] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[228])
		{
			KeyboardInput[KEY_A_UMLAUT] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[252])
		{
			KeyboardInput[KEY_U_UMLAUT] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[223])
		{
			KeyboardInput[KEY_BETA] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput['+'])
		{
			KeyboardInput[KEY_PLUS] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput['#'])
		{
			KeyboardInput[KEY_HASH] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[161])
		{
			KeyboardInput[KEY_UPSIDEDOWNEXCLAMATION] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[231])
		{
			KeyboardInput[KEY_C_CEDILLA] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[241])
		{
			KeyboardInput[KEY_N_TILDE] = TRUE;
			GotAnyKey = TRUE;
		}
		if (IngameKeyboardInput[')'])
//.........这里部分代码省略.........
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:101,代码来源:Di_func.cpp

示例11: InitialiseDirectKeyboard

BOOL InitialiseDirectKeyboard()

{    
    HRESULT  hRes;

    // try to create keyboard device
    if (lpdi->CreateDevice(guid, &lpdiKeyboard, NULL) !=DI_OK)
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4112);
	   #else
	   return FALSE;
	   #endif
      }

    // Tell DirectInput that we want to receive data in keyboard format
    if (lpdiKeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK)
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4113);
	   #else
	   return FALSE;
	   #endif
      }

    // set cooperative level
	// this level is the most likely to work across
	// multiple hardware targets
	// (i.e. this is probably best for a production
	// release)
	#if UseForegroundKeyboard
    if (lpdiKeyboard->SetCooperativeLevel(hWndMain,
                         DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK)
	#else
	// this level makes alt-tabbing multiple instances in
	// SunWindow mode possible without receiving lots
	// of false inputs
    if (lpdiKeyboard->SetCooperativeLevel(hWndMain,
                         DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK)
	#endif
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4114);
	   #else
	   return FALSE;
	   #endif
      }

    // try to acquire the keyboard
    hRes = lpdiKeyboard->Acquire();
    if (hRes == DI_OK)
      {
       // keyboard was acquired
       DIKeyboardOkay = TRUE;
      }
    else
      {
       // keyboard was NOT acquired
       DIKeyboardOkay = FALSE;
      }

    // if we get here, all objects were created successfully
    return TRUE;    
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:67,代码来源:Di_func.cpp

示例12: DirectReadMouse

void DirectReadMouse(void)
{
    DIDEVICEOBJECTDATA od[DMouse_RetrieveSize];
    DWORD dwElements = DMouse_RetrieveSize;
	HRESULT hres;
	int OldMouseX, OldMouseY, OldMouseZ;

 	GotMouse = No;
	MouseVelX = 0;
	MouseVelY = 0;
	MouseVelZ = 0;

    hres = lpdiMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),&od[0],&dwElements, 0);

    
    if (hres == DIERR_INPUTLOST || hres==DIERR_NOTACQUIRED)
	{
		// We had acquisition, but lost it.  Try to reacquire it.
		hres = lpdiMouse->Acquire();
		// No data this time
    	return;
    }

    // Unable to read data
	if (hres != DI_OK) return;

    // Check for any data being picked up
	GotMouse = Yes;
	if (dwElements == 0) return;

    // Save mouse x and y for velocity determination
	OldMouseX = MouseX;
	OldMouseY = MouseY;
	OldMouseZ = MouseZ;

    // Process all recovered elements and
	// make appropriate modifications to mouse
	// status variables.

    int i;

    for (i=0; i<dwElements; i++)
	{
	// Look at the element to see what happened

		switch (od[i].dwOfs)
		{
			// DIMOFS_X: Mouse horizontal motion
			case DIMouseXOffset:
			    MouseX += od[i].dwData;
			    break;

			// DIMOFS_Y: Mouse vertical motion
			case DIMouseYOffset: 
			    MouseY += od[i].dwData;
			    break;

			case DIMouseZOffset: 
			    MouseZ += od[i].dwData;
				textprint("z info received %d\n",MouseZ);
			    break;

			// DIMOFS_BUTTON0: Button 0 pressed or released
			case DIMouseButton0Offset:
			    if (od[i].dwData & DikOn) 
			      // Button pressed
				  MouseButton |= LeftButton;
				else
			      // Button released
				  MouseButton &= ~LeftButton;
			    break;

			// DIMOFS_BUTTON1: Button 1 pressed or released
			case DIMouseButton1Offset:
			  if (od[i].dwData & DikOn)
			      // Button pressed
				  MouseButton |= RightButton;
			  else
			      // Button released
				  MouseButton &= ~RightButton;
			  break;

			case DIMouseButton2Offset:
			case DIMouseButton3Offset:
			  if (od[i].dwData & DikOn)
			      // Button pressed
				  MouseButton |= MiddleButton;
			  else
			      // Button released
				  MouseButton &= ~MiddleButton;
			  break;
			
			default:
			  break;
		}
	}

    MouseVelX = DIV_FIXED(MouseX-OldMouseX,NormalFrameTime);
    MouseVelY = DIV_FIXED(MouseY-OldMouseY,NormalFrameTime);
    //MouseVelZ = DIV_FIXED(MouseZ-OldMouseZ,NormalFrameTime);
//.........这里部分代码省略.........
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:101,代码来源:Di_func.cpp

示例13: input_dinput_init

/**
 * input_dinput_init(): Initialize the DirectInput subsystem.
 * @return 0 on success; non-zero on error.
 */
int input_dinput_init(void)
{
	int i;
	HRESULT rval;
	
	// Attempt to initialize DirectInput 5.
	input_dinput_version = 0;
	rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_5, &lpDI, NULL);
	if (rval == DI_OK)
	{
		// DirectInput 5 initialized.
		LOG_MSG(input, LOG_MSG_LEVEL_INFO,
			"Initialized DirectInput 5.");
		input_dinput_version = DIRECTINPUT_VERSION_5;
	}
	else
	{
		// Attempt to initialize DirectInput 3.
		rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_3, &lpDI, NULL);
		if (rval == DI_OK)
		{
			// DirectInput 3 initialized.
			LOG_MSG(input, LOG_MSG_LEVEL_INFO,
				"Initialized DirectInput 3.");
			input_dinput_version = DIRECTINPUT_VERSION_3;
		}
		else
		{
			// DirectInput could not be initialized.
			LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
				"Could not initialize DirectInput 3 or DirectInput 5.\n\nYou must have DirectX 3 or later.");
			return -1;
		}
	}
	
	input_dinput_joystick_initialized = false;
	input_dinput_joystick_error = false;
	input_dinput_num_joysticks = 0;
	memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id));
	
	//rval = lpDI->CreateDevice(GUID_SysMouse, &lpDIDMouse, NULL);
	lpDIDMouse = NULL;
	rval = lpDI->CreateDevice(GUID_SysKeyboard, &lpDIDKeyboard, NULL);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDI->CreateDevice() failed. (Keyboard)");
		
		// TODO: Use cross-platform error numbers, not just DirectInput return values.
		return -2;
	}
	
	// Set the cooperative level.
	input_dinput_set_cooperative_level(NULL);
	
	//rval = lpDIDMouse->SetDataFormat(&c_dfDIMouse);
	rval = lpDIDKeyboard->SetDataFormat(&c_dfDIKeyboard);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDIDKeyboard->SetDataFormat() failed.");
		
		// TODO: Use cross-platform error numbers, not just DirectInput return values.
		return -1;
	}
	
	//rval = lpDIDMouse->Acquire();
	for(i = 0; i < 10; i++)
	{
		rval = lpDIDKeyboard->Acquire();
		if (rval == DI_OK)
			break;
		GensUI::sleep(10);
	}
	
	// Clear the DirectInput arrays.
	memset(input_dinput_keys, 0x00, sizeof(input_dinput_keys));
	memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id));
	memset(input_dinput_joy_state, 0x00, sizeof(input_dinput_joy_state));
	
	// DirectInput initialized.
	return 0;
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:87,代码来源:input_dinput.cpp

示例14: di_process

DWORD di_process(DWORD lparam)
{
	while (1) {
		if ( WaitForSingleObject( Di_event, INFINITE )==WAIT_OBJECT_0 )	{

			//mprintf(( "Got event!\n" ));

			HRESULT hr;

			DIDEVICEOBJECTDATA rgdod[10]; 
			DWORD dwItems = MAX_BUFFERED_KEYBOARD_EVENTS; 

again:;
			hr = Di_keyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), rgdod,  &dwItems, 0); 

			if (hr == DIERR_INPUTLOST) {
				/*
				*  DirectInput is telling us that the input stream has
				*  been interrupted.  We aren't tracking any state
				*  between polls, so we don't have any special reset
				*  that needs to be done.  We just re-acquire and
				*  try again.
				*/
				Sleep(1000);		// Pause a second...
				hr = Di_keyboard->Acquire();
				if (SUCCEEDED(hr)) {
					goto again;
				}
			}

			if (SUCCEEDED(hr)) { 
				 // dwItems = number of elements read (could be zero)
				 if (hr == DI_BUFFEROVERFLOW) { 
					// Buffer had overflowed. 
					mprintf(( "Buffer overflowed!\n" ));
				 } 
					int i;

					//mprintf(( "Got %d events\n", dwItems ));

					for (i=0; i<(int)dwItems; i++ )	{
						int key = rgdod[i].dwOfs;
						int state = rgdod[i].dwData;
						int stamp = rgdod[i].dwTimeStamp;

						int latency;
						latency = timeGetTime() - stamp;
						if ( latency < 0 )
							latency=0;

//						if ( key == KEY_PRINT_SCRN )	{
//							key_mark( key, 1, latency );
//						}
//						key_mark( key, (state&0x80?1:0), latency );
						mprintf(( "Key=%x, State=%x, Time=%d, Latency=%d\n", key, state, stamp, latency ));
					}

			} 
		} 

	}

	return 0;
}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:64,代码来源:key.cpp

示例15: di_init


//.........这里部分代码省略.........
     *          Receives pointer to the IDirectInputDevice interface
     *          that was created.
     *
     *      NULL
     *
     *          We do not use OLE aggregation, so this parameter
     *          must be NULL.
     *
     */
    hr = Di_object->CreateDevice(GUID_SysKeyboard, &Di_keyboard, NULL);

    if (FAILED(hr)) {
        mprintf(( "CreateDevice failed!\n" ));
        return FALSE;
    }

    /*
     *  Set the data format to "keyboard 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 an array
     *  of 256 bytes to IDirectInputDevice::GetDeviceState.
     *
     *  Parameters:
     *
     *      c_dfDIKeyboard
     *
     *          Predefined data format which describes
     *          an array of 256 bytes, one per scancode.
     */
    hr = Di_keyboard->SetDataFormat(&c_dfDIKeyboard);

    if (FAILED(hr)) {
        mprintf(( "SetDataFormat failed!\n" ));
        return FALSE;
    }


    /*
     *  Set the cooperativity level to let DirectInput know how
     *  this device should interact with the system and with other
     *  DirectInput applications.
     *
     *  Parameters:
     *
     *      DISCL_NONEXCLUSIVE
     *
     *          Retrieve keyboard data when acquired, not interfering
     *          with any other applications which are reading keyboard
     *          data.
     *
     *      DISCL_FOREGROUND
     *
     *          If the user switches away from our application,
     *          automatically release the keyboard back to the system.
     *
     */
	hr = Di_keyboard->SetCooperativeLevel((HWND)os_get_window(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);

	if (FAILED(hr)) {
		mprintf(( "SetCooperativeLevel failed!\n" ));
		return FALSE;
	}

	DIPROPDWORD hdr;

	// Turn on buffering
	hdr.diph.dwSize = sizeof(DIPROPDWORD); 
	hdr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
	hdr.diph.dwObj = 0;		
	hdr.diph.dwHow = DIPH_DEVICE;	// Apply to entire device
	hdr.dwData = 16;	//MAX_BUFFERED_KEYBOARD_EVENTS;

	hr = Di_keyboard->SetProperty( DIPROP_BUFFERSIZE, &hdr.diph );
	if (FAILED(hr)) {
		mprintf(( "SetProperty DIPROP_BUFFERSIZE failed\n" ));
		return FALSE;
	}


	Di_event = CreateEvent( NULL, FALSE, FALSE, NULL );
	Assert(Di_event != NULL);

	Di_thread = CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)di_process, NULL, 0, &Di_thread_id);
	Assert( Di_thread != NULL );

	SetThreadPriority(Di_thread, THREAD_PRIORITY_HIGHEST);

	hr = Di_keyboard->SetEventNotification(Di_event);
	if (FAILED(hr)) {
		mprintf(( "SetEventNotification failed\n" ));
		return FALSE;
	}

	Di_keyboard->Acquire();

	return TRUE;
}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:101,代码来源:key.cpp


注:本文中的LPDIRECTINPUTDEVICE::Acquire方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。