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


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

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


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

示例1: 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

示例2: PisteInput_Hae_Hiiri

bool PisteInput_Hae_Hiiri()
{
	if (PI_mouse_available)
	{
		if (FAILED(PI_lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&PI_mouse_state)))
		{
			PisteLog_Kirjoita("[Warning] Piste Input: Lost control of mouse! \n");
			PI_mouse_available = false;
		}
	}
	return PI_mouse_available;
}
开发者ID:stt,项目名称:pk2,代码行数:12,代码来源:PisteInput.cpp

示例3: 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

示例4: 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

示例5: input_dinput_update

/**
 * input_dinput_update(): Update the input subsystem.
 * @return 0 on success; non-zero on error.
 */
int input_dinput_update(void)
{
	//DIMOUSESTATE MouseState;
	HRESULT rval;
	
	rval = lpDIDKeyboard->GetDeviceState(256, &input_dinput_keys);
	
	// HACK because DirectInput is totally wacky about recognizing the PAUSE/BREAK key
	// still not perfect with this, but at least it goes above a 25% success rate
	if(GetAsyncKeyState(VK_PAUSE)) // normally this should have & 0x8000, but apparently this key is too special for that to work
		input_dinput_keys[0xC5] |= 0x80;
	
	if ((rval == DIERR_INPUTLOST) | (rval == DIERR_NOTACQUIRED))
		input_dinput_restore_input();
	
	for (int i = 0; i < input_dinput_num_joysticks; i++)
	{
		if (input_dinput_joy_id[i])
		{
			input_dinput_joy_id[i]->Poll();
			rval = input_dinput_joy_id[i]->GetDeviceState(sizeof(input_dinput_joy_state[i]), &input_dinput_joy_state[i]);
			if (rval != DI_OK) input_dinput_joy_id[i]->Acquire();
		}
	}
	
	return 0;
	
	// TODO: Figure out what to do with the rest of this function.
	
	//rval = lpDIDMouse->GetDeviceState(sizeof(MouseState), &MouseState);
	
	//if ((rval == DIERR_INPUTLOST) | (rval == DIERR_NOTACQUIRED))
	//	Restore_Input();

	//MouseX = MouseState.lX;
	//MouseY = MouseState.lY;
	
	// TODO: This is from Gens/Rerecording's hotkey remapping system.
#if 0
	int numInputButtons = GetNumHotkeys();
	for(int i = 0; i < numInputButtons; i++)
	{
		InputButton& button = s_inputButtons[i];

		BOOL pressed = button.diKey ? Check_Key_Pressed(button.diKey) : FALSE;

		if(button.virtKey || button.modifiers)
		{
			bool pressed2 = button.virtKey ? !!(GetAsyncKeyState(button.virtKey) & 0x8000) : true;

			pressed2 &= !(button.modifiers & MOD_CONTROL) == !(GetAsyncKeyState(VK_CONTROL) & 0x8000);
			pressed2 &= !(button.modifiers & MOD_SHIFT) == !(GetAsyncKeyState(VK_SHIFT) & 0x8000);
			pressed2 &= !(button.modifiers & MOD_ALT) == !(GetAsyncKeyState(VK_MENU) & 0x8000);
			pressed2 &= !(button.modifiers & MOD_WIN) == !((GetAsyncKeyState(VK_LWIN)|GetAsyncKeyState(VK_RWIN)) & 0x8000);

			if(!button.diKey)
				pressed = TRUE;

			if(!pressed2)
				pressed = FALSE;
		}

		if (button.alias)
			*button.alias = pressed;

		BOOL oldPressed = button.heldNow;
		button.heldNow = pressed;

		if (pressed && !oldPressed && button.eventID && !button.ShouldUseAccelerator())
			SendMessage(gens_window, WM_COMMAND, button.eventID, 0);
	}
#endif
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:77,代码来源:input_dinput.cpp

示例6: 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


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