• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ KeyState函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中KeyState函数的典型用法代码示例。如果您正苦于以下问题:C++ KeyState函数的具体用法?C++ KeyState怎么用?C++ KeyState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: KeyState

/*
==============================
AdjustPitch

==============================
*/
void CInput::AdjustPitch( float speed, QAngle& viewangles )
{
	// only allow keyboard looking if mouse look is disabled
	if ( UsingMouselook() == false )
	{
		float	up, down;

		if ( in_klook.state & 1 )
		{
			view->StopPitchDrift ();
			viewangles[PITCH] -= speed*cl_pitchspeed.GetFloat() * KeyState (&in_forward);
			viewangles[PITCH] += speed*cl_pitchspeed.GetFloat() * KeyState (&in_back);
		}

		up		= KeyState ( &in_lookup );
		down	= KeyState ( &in_lookdown );
		
		viewangles[PITCH] -= speed*cl_pitchspeed.GetFloat() * up;
		viewangles[PITCH] += speed*cl_pitchspeed.GetFloat() * down;

		if ( up || down )
		{
			view->StopPitchDrift ();
		}
	}	
}
开发者ID:jimbomcb,项目名称:BirdPoop-Src,代码行数:32,代码来源:in_main.cpp


示例2: KeyState

void InputManager::OnInitialize()
{
    Keys[SDLK_w] = KeyState();
    Keys[SDLK_a] = KeyState();
    Keys[SDLK_s] = KeyState();
    Keys[SDLK_d] = KeyState();
}
开发者ID:kametman,项目名称:aether,代码行数:7,代码来源:inputmanager.cpp


示例3: PrintEvent

static void PrintEvent(const Event& event)
{
    switch (event.Type)
    {
      case Event::EVENT_CLOSED:
        std::cout << "Event: Window Closed" << std::endl;
        break;
      case Event::EVENT_MOVED:
        std::cout << "Event: Window Moved (" << event.Move.X
                  << ", " << event.Move.Y << ")" << std::endl;
        break;
      case Event::EVENT_RESIZED:
        std::cout << "Event: Window Resized (" << event.Size.Width
                  << ", " << event.Size.Height << ")" << std::endl;
        break;
      case Event::EVENT_LOST_FOCUS:
        std::cout << "Event: Window Lost Focus" << std::endl;
        break;
      case Event::EVENT_GAINED_FOCUS:
        std::cout << "Event: Window Gained Focus" << std::endl;
        break;
      case Event::EVENT_TEXT_ENTERED:
        // TODO(cwallez) show the character
        std::cout << "Event: Text Entered" << std::endl;
        break;
      case Event::EVENT_KEY_PRESSED:
        std::cout << "Event: Key Pressed (" << KeyName(event.Key.Code) << KeyState(event.Key) << ")" << std::endl;
        break;
      case Event::EVENT_KEY_RELEASED:
        std::cout << "Event: Key Released (" << KeyName(event.Key.Code) << KeyState(event.Key) << ")" << std::endl;
        break;
      case Event::EVENT_MOUSE_WHEEL_MOVED:
        std::cout << "Event: Mouse Wheel (" << event.MouseWheel.Delta << ")" << std::endl;
        break;
      case Event::EVENT_MOUSE_BUTTON_PRESSED:
        std::cout << "Event: Mouse Button Pressed " << MouseButtonName(event.MouseButton.Button) <<
                  " at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
        break;
      case Event::EVENT_MOUSE_BUTTON_RELEASED:
        std::cout << "Event: Mouse Button Released " << MouseButtonName(event.MouseButton.Button) <<
                  " at (" << event.MouseButton.X << ", " << event.MouseButton.Y << ")" << std::endl;
        break;
      case Event::EVENT_MOUSE_MOVED:
        std::cout << "Event: Mouse Moved (" << event.MouseMove.X
                  << ", " << event.MouseMove.Y << ")" << std::endl;
        break;
      case Event::EVENT_MOUSE_ENTERED:
        std::cout << "Event: Mouse Entered Window" << std::endl;
        break;
      case Event::EVENT_MOUSE_LEFT:
        std::cout << "Event: Mouse Left Window" << std::endl;
        break;
      case Event::EVENT_TEST:
        std::cout << "Event: Test" << std::endl;
        break;
      default:
        UNREACHABLE();
        break;
    }
}
开发者ID:CODECOMMUNITY,项目名称:angle,代码行数:60,代码来源:OSWindow.cpp


示例4: KeyState

/*
==============================
ComputeForwardMove

==============================
*/
void CInput::ComputeForwardMove( CUserCmd *cmd )
{
    if ( !(in_klook.state & 1 ) )
    {
        cmd->forwardmove += cl_forwardspeed.GetFloat() * KeyState (&in_forward);
        cmd->forwardmove -= cl_backspeed.GetFloat() * KeyState (&in_back);
    }
}
开发者ID:xsopher,项目名称:VinHax,代码行数:14,代码来源:in_main.cpp


示例5: StopMap

VOID StopMap(BOOL ResetShiftKeys)
{
	AbbrevDeletes = QueuedChars = SequenceLen = PendingDown = 0;
	if (ResetShiftKeys) {
		if (GetKeyState(VK_CONTROL)	< 0) KeyState(VK_CONTROL, FALSE);
		if (GetKeyState(VK_SHIFT)	< 0) KeyState(VK_SHIFT,	  FALSE);
		if (GetKeyState(VK_MENU)	< 0) KeyState(VK_MENU,	  FALSE);
		FinalKeyState = 0;
	}
}
开发者ID:mike2718,项目名称:WinVi,代码行数:10,代码来源:Map.c


示例6: MousePos

	MouseState MouseState::GetState()
	{
		MouseState ms;

		ms.position = MousePos();
		ms.buttons[BUTTON_LEFT]		= KeyState(VK_LBUTTON);
		ms.buttons[BUTTON_MIDDLE]	= KeyState(VK_MBUTTON);
		ms.buttons[BUTTON_RIGHT]	= KeyState(VK_RBUTTON);

		return ms;
	};
开发者ID:SoundAxis,项目名称:Wrench.2014,代码行数:11,代码来源:MouseState.cpp


示例7: int

KeyboardState::KeyboardState()
{
    // NOTE(Wuxiang): Copy from the Key enum value.
    static std::vector<int> sKeyCode = { 32, 39, 44, 45, 46, 47, 48, 49, 50, 51,
                                         52, 53, 54, 55, 56, 57, 59, 61, 65, 66,
                                         67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
                                         77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
                                         87, 88, 89, 90, 91, 92, 93, 96, 161, 162,
                                         256, 257, 258, 259, 260, 261, 262, 263,
                                         264, 265, 266, 267, 268, 269, 280, 281,
                                         282, 283, 284, 290, 291, 292, 293, 294,
                                         295, 296, 297, 298, 299, 300, 301, 302,
                                         303, 304, 305, 306, 307, 308, 309, 310,
                                         311, 312, 313, 314, 320, 321, 322, 323,
                                         324, 325, 326, 327, 328, 329, 330, 331,
                                         332, 333, 334, 335, 336, 340, 341, 342,
                                         343, 344, 345, 346, 347, 348
                                       };

    int keyNum = int(sKeyCode.size());
    for (int keyIndex = 0; keyIndex < keyNum ; ++keyIndex)
    {
        auto key = Key(sKeyCode[keyIndex]);
        insert({ key, KeyState(key) });
    }
}
开发者ID:Lywx,项目名称:FalconEngine,代码行数:26,代码来源:KeyboardState.cpp


示例8: CalcButtonBits

/*
============
GetButtonBits

Returns appropriate button info for keyboard and mouse state
Set bResetState to 1 to clear old state info
============
*/
int CInput::GetButtonBits( int bResetState )
{
	int bits = 0;

	CalcButtonBits( bits, IN_SPEED, s_ClearInputState, &in_speed, bResetState );
	CalcButtonBits( bits, IN_WALK, s_ClearInputState, &in_walk, bResetState );
	CalcButtonBits( bits, IN_ATTACK, s_ClearInputState, &in_attack, bResetState );
	CalcButtonBits( bits, IN_DUCK, s_ClearInputState, &in_duck, bResetState );
	CalcButtonBits( bits, IN_JUMP, s_ClearInputState, &in_jump, bResetState );
	CalcButtonBits( bits, IN_FORWARD, s_ClearInputState, &in_forward, bResetState );
	CalcButtonBits( bits, IN_BACK, s_ClearInputState, &in_back, bResetState );
	CalcButtonBits( bits, IN_USE, s_ClearInputState, &in_use, bResetState );
	CalcButtonBits( bits, IN_LEFT, s_ClearInputState, &in_left, bResetState );
	CalcButtonBits( bits, IN_RIGHT, s_ClearInputState, &in_right, bResetState );
	CalcButtonBits( bits, IN_MOVELEFT, s_ClearInputState, &in_moveleft, bResetState );
	CalcButtonBits( bits, IN_MOVERIGHT, s_ClearInputState, &in_moveright, bResetState );
	CalcButtonBits( bits, IN_ATTACK2, s_ClearInputState, &in_attack2, bResetState );
	CalcButtonBits( bits, IN_RELOAD, s_ClearInputState, &in_reload, bResetState );
	CalcButtonBits( bits, IN_ALT1, s_ClearInputState, &in_alt1, bResetState );
	CalcButtonBits( bits, IN_ALT2, s_ClearInputState, &in_alt2, bResetState );
	CalcButtonBits( bits, IN_SCORE, s_ClearInputState, &in_score, bResetState );
	CalcButtonBits( bits, IN_ZOOM, s_ClearInputState, &in_zoom, bResetState );
	CalcButtonBits( bits, IN_GRENADE1, s_ClearInputState, &in_grenade1, bResetState );
	CalcButtonBits( bits, IN_GRENADE2, s_ClearInputState, &in_grenade2, bResetState );
	CalcButtonBits( bits, IN_TOPSPIN, s_ClearInputState, &in_topspin, bResetState );
	CalcButtonBits( bits, IN_BACKSPIN, s_ClearInputState, &in_backspin, bResetState);
	CalcButtonBits( bits, IN_SKILL, s_ClearInputState, &in_skill, bResetState );
	CalcButtonBits( bits, IN_GESTURE, s_ClearInputState, &in_gesture, bResetState );

	if ( KeyState(&in_ducktoggle) )
	{
		bits |= IN_DUCK;
	}

	// Cancel is a special flag
	if (in_cancel)
	{
		bits |= IN_CANCEL;
	}

	if ( gHUD.m_iKeyBits & IN_WEAPON1 )
	{
		bits |= IN_WEAPON1;
	}

	if ( gHUD.m_iKeyBits & IN_WEAPON2 )
	{
		bits |= IN_WEAPON2;
	}

	// Clear out any residual
	bits &= ~s_ClearInputState;

	if ( bResetState )
	{
		s_ClearInputState = 0;
	}

	return bits;
}
开发者ID:iosoccer,项目名称:iosoccer-game,代码行数:68,代码来源:in_main.cpp


示例9: switch

bool KeyStateListener::eventFilter (QObject *obj, QEvent *event)
{
    switch (event-> type())
    {
        case QEvent::KeyPress:
            press_key_ (KeyState (static_cast <QKeyEvent *> (event)));
            return false;

        case QEvent::KeyRelease:
            release_key_ (KeyState (static_cast <QKeyEvent *> (event)));
            return false;

        default:
            return QObject::eventFilter (obj, event);
    }
}
开发者ID:sempuki,项目名称:code,代码行数:16,代码来源:main.cpp


示例10: RenderStreamToSurface

bool SINMOVIE::RenderStreamToSurface()
{
if (KeyState(VK_RETURN)) {  MovieState=2; ShutDown();return false; } 
if (pSample->Update(0, NULL, NULL, 0) != S_OK) {  MovieState=2; ShutDown(); return 
false; } 
pMovieSurface->Blt(&DRect, pSurface, &SRect, DDBLT_WAIT, NULL); 
return true;
}
开发者ID:rafaellincoln,项目名称:Source-Priston-Tale,代码行数:8,代码来源:sinMedia.cpp


示例11: while

void SINMOVIE::RenderStreamToSurfaceAll()
{
while (1)
{
  if (KeyState(VK_RETURN)) {  MovieState=2; ShutDown(); return; } 
  if (pSample->Update(0, NULL, NULL, 0) != S_OK) {  MovieState=2; ShutDown(); return; } 
  pMovieSurface->Blt(&DRect, pSurface, &SRect, DDBLT_WAIT, NULL); 
}
}
开发者ID:rafaellincoln,项目名称:Source-Priston-Tale,代码行数:9,代码来源:sinMedia.cpp


示例12: WndProc

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
		case WM_MOVE:
		case WM_SIZE:
			Utility::resize();
			break;
		case WM_CHAR:
			DeveloperConsole::catchCharacter((wchar_t)wParam);
			break;
		case WM_KEYDOWN:
			// check which key is pressed
			InputManager::keyDown(KeyState(wParam, lParam));
			switch(wParam)
			{
				case VK_F5:
					dx.toggleFullScreen();	
					break;
				case VK_F4: 
					killProgram();
					break;
			}
			break;
		case WM_COMMAND:
			wmId    = LOWORD(wParam);
			wmEvent = HIWORD(wParam);
			// Parse the menu selections:
			switch (wmId)
			{
			case IDM_ABOUT:
				DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
				break;
			case IDM_EXIT:
				DestroyWindow(hWnd);
				break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// Add any drawing code here...
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			killProgram();
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
开发者ID:mcmonkey,项目名称:cglory,代码行数:67,代码来源:BaseCode.cpp


示例13: AnimData

GameScene::GameScene(const std::string& level)
{
    background_data_ = new AnimData("assets/background");
    background_ = new Animation(*background_data_);

    music_notes_.push_back(new Entity("musicnote0"));
    music_notes_.push_back(new Entity("musicnote1"));
    music_notes_.push_back(new Entity("musicnote2"));

    player_keys_.left = KeyState(sf::Key::Left);
    player_keys_.right = KeyState(sf::Key::Right);
    player_keys_.up = KeyState(sf::Key::Up);
    player_keys_.down = KeyState(sf::Key::Down);
    player_keys_.action = KeyState(sf::Key::Space);

    level_name_ = level;

    music_note_timer_ = 0.0f;
}
开发者ID:nlguillemot,项目名称:rock-n-roll-soul,代码行数:19,代码来源:gamescene.cpp


示例14: KeyScan

void KeyScan(){
  if(~PINC&0b00000111){ // обработчик нажатия
    flags.KeyReleased=0;
        if (++i > 5 ) {      //короткое нажатие 100-250 миллисекунд
            if (!flags.KeyPressed){flags.KeyPressed = 1;flags.KeyPin=(~PINC&0b00000111);}
               if ( i > 100 ){  //длинное нажатие 1-3 секунды
                 if (!flags.KeyPushLong){

                    flags.KeyPushLong=1;
                    KeyState();
                 }
               }
        }
    }
    else {
        i=0;
        if (!flags.KeyReleased) {flags.KeyReleased=1;}
        KeyState();
    }
        AddTask(KeyScan,25);
}
开发者ID:4glk,项目名称:at8_ct,代码行数:21,代码来源:kbd.c


示例15: KeyScan

void KeyScan(){
    volatile static uint8_t k=0;
  if(KEY_CODE){ // обработчик нажатия
    flags.KeyReleased=0;
        if (++k >=2 ) {      //короткое нажатие 100-250 миллисекунд
            if (!flags.KeyPressed){flags.KeyPressed = 1;flags.KeyPin=(KEY_CODE);}
               if ( k > 100 ){  //длинное нажатие 1-3 секунды
                 if (!flags.KeyPushLong){
                    k=0;                // проблема с этой переменной , конфликтует с енумом кнопок (((
                    flags.KeyPushLong=1;
                    KeyState();
                 }
               }
        }
    }
    else {
        k=0;
        if (!flags.KeyReleased) {flags.KeyReleased=1;}
        KeyState();
    }
    AddTask(KeyScan,50);
}
开发者ID:4glk,项目名称:low_temp,代码行数:22,代码来源:kbd.c


示例16: updatebutton

void updatebutton(string &name, bool on, int posfinger)
{
    auto kmit = keymap.find(name);
    auto ks = &(kmit != keymap.end() ? kmit : keymap.insert(make_pair(name, KeyState())).first)->second;
    ks->isdown = on;
    if (on)
    {
        ks->wentdown = true;
    }
    else
    {
        ks->wentup = true;
    }
    ks->lasttime[on] = lastmillis;
    ks->lastpos[on] = fingers[posfinger].mousepos;
}
开发者ID:slagusev,项目名称:lobster,代码行数:16,代码来源:sdlsystem.cpp


示例17: sin

/*
==============================
ComputeSideMove

==============================
*/
void CInput::ComputeSideMove( CUserCmd *cmd )
{
	// thirdperson platformer movement
	if ( CAM_IsThirdPerson() && thirdperson_platformer.GetInt() )
	{
		// no sideways movement in this mode
		return;
	}

	// thirdperson screenspace movement
	if ( CAM_IsThirdPerson() && thirdperson_screenspace.GetInt() )
	{
		float ideal_yaw = m_aCamIdealAngles[YAW];
		float ideal_sin = sin(DEG2RAD(ideal_yaw));
		float ideal_cos = cos(DEG2RAD(ideal_yaw));
		
		float movement = ideal_cos*KeyState(&in_moveright)
			+  ideal_sin*KeyState(&in_back)
			+ -ideal_cos*KeyState(&in_moveleft)
			+ -ideal_sin*KeyState(&in_forward);

		cmd->sidemove += cl_sidespeed.GetFloat() * movement;

		return;
	}

	// If strafing, check left and right keys and act like moveleft and moveright keys
	if ( in_strafe.state & 1 )
	{
		cmd->sidemove += cl_sidespeed.GetFloat() * KeyState (&in_right);
		cmd->sidemove -= cl_sidespeed.GetFloat() * KeyState (&in_left);
	}

	// Otherwise, check strafe keys

	C_SDKPlayer *pPlayer = ToSDKPlayer(C_BasePlayer::GetLocalPlayer());

	cmd->sidemove += cl_sidespeed.GetFloat() * KeyState (&in_moveright);
	cmd->sidemove -= cl_sidespeed.GetFloat() * KeyState (&in_moveleft);
}
开发者ID:iosoccer,项目名称:iosoccer-game,代码行数:46,代码来源:in_main.cpp


示例18: CheckKeys

//================================================================================
ATHKeyList ATHInputManager::CheckKeys()
{
	std::list< unsigned int > liKeysDown;

	BYTE chAsciiKeys[ ATH_NUM_KEYS ] = {};
	if( GetKeyboardState( chAsciiKeys ) )
	{
		for(unsigned int i = 0; i < ATH_NUM_KEYS; i++)
		{
			if( KeyState( (unsigned char)(i) ) )
			{
				unsigned int nVKCode = MapVirtualKeyEx(i, MAPVK_VSC_TO_VK, NULL );

				liKeysDown.push_back(i);
			}
		}
	}

	return liKeysDown;
}
开发者ID:Ethanthecrazy,项目名称:ATHEngine,代码行数:21,代码来源:ATHInputManager.cpp


示例19: while

void Pi::HandleEvents()
{
	SDL_Event event;

	Pi::mouseMotion[0] = Pi::mouseMotion[1] = 0;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			if (Pi::game)
				Pi::EndGame();
			Pi::Quit();
		}
		else if (ui->DispatchSDLEvent(event))
			continue;

		Gui::HandleSDLEvent(&event);
		if (!Pi::IsConsoleActive())
			KeyBindings::DispatchSDLEvent(&event);
		else
			KeyBindings::toggleLuaConsole.CheckSDLEventAndDispatch(&event);

		switch (event.type) {
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_ESCAPE) {
					if (Pi::game) {
						// only accessible once game started
						if (currentView != 0) {
							if (currentView != gameMenuView) {
								Pi::game->SetTimeAccel(Game::TIMEACCEL_PAUSED);
								SetView(gameMenuView);
							}
							else {
								Pi::game->RequestTimeAccel(Game::TIMEACCEL_1X);
								SetView(Pi::player->IsDead()
										? static_cast<View*>(deathView)
										: static_cast<View*>(worldView));
							}
						}
					}
					break;
				}
				// special keys. LCTRL+turd
				if ((KeyState(SDLK_LCTRL) || (KeyState(SDLK_RCTRL)))) {
					switch (event.key.keysym.sym) {
						case SDLK_q: // Quit
							if (Pi::game)
								Pi::EndGame();
							Pi::Quit();
							break;
						case SDLK_PRINT:	   // print
						case SDLK_KP_MULTIPLY: // screen
						{
							char buf[256];
							const time_t t = time(0);
							struct tm *_tm = localtime(&t);
							strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%H%M%S.png", _tm);
							Screendump(buf, Graphics::GetScreenWidth(), Graphics::GetScreenHeight());
							break;
						}
#if WITH_DEVKEYS
						case SDLK_i: // Toggle Debug info
							Pi::showDebugInfo = !Pi::showDebugInfo;
							break;
						case SDLK_m:  // Gimme money!
							if(Pi::game) {
								Pi::player->SetMoney(Pi::player->GetMoney() + 10000000);
							}
							break;
						case SDLK_F12:
						{
							if(Pi::game) {
								vector3d dir = -Pi::player->GetOrient().VectorZ();
								/* add test object */
								if (KeyState(SDLK_RSHIFT)) {
									Missile *missile =
										new Missile(ShipType::MISSILE_GUIDED, Pi::player, Pi::player->GetCombatTarget());
									missile->SetOrient(Pi::player->GetOrient());
									missile->SetFrame(Pi::player->GetFrame());
									missile->SetPosition(Pi::player->GetPosition()+50.0*dir);
									missile->SetVelocity(Pi::player->GetVelocity());
									game->GetSpace()->AddBody(missile);
								} else if (KeyState(SDLK_LSHIFT)) {
									SpaceStation *s = static_cast<SpaceStation*>(Pi::player->GetNavTarget());
									if (s) {
										int port = s->GetFreeDockingPort();
										if (port != -1) {
											printf("Putting ship into station\n");
											// Make police ship intent on killing the player
											Ship *ship = new Ship(ShipType::LADYBIRD);
											ship->AIKill(Pi::player);
											ship->SetFrame(Pi::player->GetFrame());
											ship->SetDockedWith(s, port);
											game->GetSpace()->AddBody(ship);
										} else {
											printf("No docking ports free dude\n");
										}
									} else {
											printf("Select a space station...\n");
									}
								} else {
									Ship *ship = new Ship(ShipType::LADYBIRD);
//.........这里部分代码省略.........
开发者ID:bitplane,项目名称:pioneer,代码行数:101,代码来源:Pi.cpp


示例20: PROFILE_SCOPED

void Pi::HandleEvents()
{
	PROFILE_SCOPED()
	SDL_Event event;

	// XXX for most keypresses SDL will generate KEYUP/KEYDOWN and TEXTINPUT
	// events. keybindings run off KEYUP/KEYDOWN. the console is opened/closed
	// via keybinding. the console TextInput widget uses TEXTINPUT events. thus
	// after switching the console, the stray TEXTINPUT event causes the
	// console key (backtick) to appear in the text entry field. we hack around
	// this by setting this flag if the console was switched. if its set, we
	// swallow the TEXTINPUT event this hack must remain until we have a
	// unified input system
	bool skipTextInput = false;

	Pi::mouseMotion[0] = Pi::mouseMotion[1] = 0;
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT) {
			if (Pi::game)
				Pi::EndGame();
			Pi::Quit();
		}

		if (skipTextInput && event.type == SDL_TEXTINPUT) {
			skipTextInput = false;
			continue;
		}
		if (ui->DispatchSDLEvent(event))
			continue;

		bool consoleActive = Pi::IsConsoleActive();
		if (!consoleActive)
			KeyBindings::DispatchSDLEvent(&event);
		else
			KeyBindings::toggleLuaConsole.CheckSDLEventAndDispatch(&event);
		if (consoleActive != Pi::IsConsoleActive()) {
			skipTextInput = true;
			continue;
		}

		if (Pi::IsConsoleActive())
			continue;

		Gui::HandleSDLEvent(&event);

		switch (event.type) {
			case SDL_KEYDOWN:
				if (event.key.keysym.sym == SDLK_ESCAPE) {
					if (Pi::game) {
						// only accessible once game started
						if (currentView != 0) {
							if (currentView != Pi::game->GetSettingsView()) {
								Pi::game->SetTimeAccel(Game::TIMEACCEL_PAUSED);
								SetView(Pi::game->GetSettingsView());
							}
							else {
								Pi::game->RequestTimeAccel(Game::TIMEACCEL_1X);
								SetView(Pi::player->IsDead()
										? static_cast<View*>(Pi::game->GetDeathView())
										: static_cast<View*>(Pi::game->GetWorldView()));
							}
						}
					}
					break;
				}
				// special keys. LCTRL+turd
				if ((KeyState(SDLK_LCTRL) || (KeyState(SDLK_RCTRL)))) {
					switch (event.key.keysym.sym) {
						case SDLK_q: // Quit
							if (Pi::game)
								Pi::EndGame();
							Pi::Quit();
							break;
						case SDLK_PRINTSCREEN: // print
						case SDLK_KP_MULTIPLY: // screen
						{
							char buf[256];
							const time_t t = time(0);
							struct tm *_tm = localtime(&t);
							strftime(buf, sizeof(buf), "screenshot-%Y%m%d-%H%M%S.png", _tm);
							Graphics::ScreendumpState sd;
							Pi::renderer->Screendump(sd);
							write_screenshot(sd, buf);
							break;
						}
#if WITH_DEVKEYS
						case SDLK_i: // Toggle Debug info
							Pi::showDebugInfo = !Pi::showDebugInfo;
							break;

#ifdef PIONEER_PROFILER
						case SDLK_p: // alert it that we want to profile
							if (KeyState(SDLK_LSHIFT) || KeyState(SDLK_RSHIFT))
								Pi::doProfileOne = true;
							else {
								Pi::doProfileSlow = !Pi::doProfileSlow;
								Output("slow frame profiling %s\n", Pi::doProfileSlow ? "enabled" : "disabled");
							}
							break;
#endif
//.........这里部分代码省略.........
开发者ID:lwho,项目名称:pioneer,代码行数:101,代码来源:Pi.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ KeyUp函数代码示例发布时间:2022-05-30
下一篇:
C++ KeyPress函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap