bool Application::GetKeyboardUpdate() { if(IsKeyPressed('A')) { scene->UpdateCameraStatus('a'); } if(IsKeyPressed('D')) { scene->UpdateCameraStatus('d'); } if(IsKeyPressed('W')) { scene->UpdateCameraStatus('w'); } else { scene->UpdateCameraStatus('w', false); } if(IsKeyPressed('S')) { scene->UpdateCameraStatus('s'); } if(IsKeyPressed(32)) { scene->UpdateCameraStatus(32); } return true; }
//! Returns current modifier keys pressed, using win32 MOD_* flags. unsigned GetHotkeyModifierFlags() { unsigned ret = 0; if (IsKeyPressed(VK_CONTROL)) ret |= MOD_CONTROL; if (IsKeyPressed(VK_SHIFT)) ret |= MOD_SHIFT; if (IsKeyPressed(VK_MENU)) ret |= MOD_ALT; if (IsKeyPressed(VK_LWIN) || IsKeyPressed(VK_RWIN)) ret |= MOD_WIN; return ret; }
void InputManager::UpdateVirtualAxisFromKeyboard(int i) { if (IsKeyPressed(_myVirtualAxis[i].positiveAxis)) _myVirtualAxis[i].state=1.0; else if (IsKeyPressed(_myVirtualAxis[i].negativeAxis)) _myVirtualAxis[i].state=-1.0; else _myVirtualAxis[i].state=0.0; }
static void WaitForKeyRelease (void) { if (IsKeyPressed()) while (IsKeyPressed()) { BE_ST_BiosScanCode(0); //getch(); } }
// Update function for this object type void RedSquareUpdate ( REDSQUARE *self ) { COLLISION_FLAG flag = CheckHotspotCollision( self->rect_ ); char buffer[100] = { 0 }; // Apply acceleration for keystrokes // Documentation for physics: http://cecilsunkure.blogspot.com/2012/02/basic-2d-vector-physics.html // Documentation for collisions: http://cecilsunkure.blogspot.com/2012/07/collision-basic-2d-collision-detection.html // http://cecilsunkure.blogspot.com/2012/04/binary-collision-maps-platformer.html if(IsKeyPressed( VK_RIGHT )) { self->vel_.x_ += self->accel_ * GetDT( ); } if(IsKeyPressed( VK_LEFT )) { self->vel_.x_ += -self->accel_ * GetDT( ); } if(IsKeyPressed( VK_UP )) { self->vel_.y_ += -self->accel_ * GetDT( ); } if(IsKeyPressed( VK_DOWN )) { self->vel_.y_ += self->accel_ * GetDT( ); } // Clamp velocity within a max/min range VelocityClamp( &self->vel_, .02f ); self->rect_.center_.x_ += self->vel_.x_ * GetDT( ); self->rect_.center_.y_ += self->vel_.y_ * GetDT( ); sprintf( buffer, "%.3f, %.3f", self->vel_.x_, self->vel_.y_ ); WriteStringToScreen( buffer, 30, 30 ); if(flag & COLLISION_BOTTOM) { SnapToCell( &self->rect_.center_.y_ ); self->vel_.y_ = 0.f; } if(flag & COLLISION_TOP) { SnapToCell( &self->rect_.center_.y_ ); self->vel_.y_ = 0.f; } if(flag & COLLISION_LEFT) { SnapToCell( &self->rect_.center_.x_ ); self->vel_.x_ = 0.f; } if(flag & COLLISION_RIGHT) { SnapToCell( &self->rect_.center_.x_ ); self->vel_.x_ = 0.f; } }
bool Application::getKeyboardUpdate() { if(IsKeyPressed('W')) scene->UpdateInput('w'); if(IsKeyPressed('A')) scene->UpdateInput('a'); if(IsKeyPressed('S')) scene->UpdateInput('s'); if(IsKeyPressed('D')) scene->UpdateInput('d'); for (unsigned char i = '1'; i <= '9'; ++i) { if (IsKeyPressed(i)) scene->UpdateInput(i); } if(IsKeyPressed(VK_SPACE)) scene->UpdateInput(' '); if(IsKeyPressed(VK_SHIFT)) scene->UpdateInput('S'); if(IsKeyPressed(VK_CONTROL)) scene->UpdateInput('C'); if (IsKeyPressed(VK_RETURN)) scene->UpdateInput('R'); return true; }
static bool should_relay_key_restricted(UINT p_key) { switch(p_key) { case VK_LEFT: case VK_RIGHT: case VK_UP: case VK_DOWN: return false; default: return (p_key >= VK_F1 && p_key <= VK_F24) || IsKeyPressed(VK_CONTROL) || IsKeyPressed(VK_LWIN) || IsKeyPressed(VK_RWIN); } }
void Controller::UpdateKeys() { /** Set all keys to false **/ for(unsigned i = 0; i < TOTAL_CONTROLS; ++i) myKeys[i] = false; /**** See which keys are pressed ****/ /** Keyboard **/ for(int i = 0; i <= OPEN; ++i) { if(IsKeyPressed(inputChar[i])) myKeys[i] = true; } /** non-keyboard(mouse) **/ mouseLeftButton = glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_LEFT); mouseRightButton = glfwGetMouseButton(glfwGetCurrentContext(), GLFW_MOUSE_BUTTON_RIGHT); if(mouseLeftButton == GLFW_PRESS) myKeys[SHOOT] = true; if(mouseRightButton == GLFW_PRESS) myKeys[AIM] = true; /** Arrow key **/ if( IsKeyPressed(VK_UP) ) myKeys[ARROW_UP] = true; if( IsKeyPressed(VK_DOWN) ) myKeys[ARROW_DOWN] = true; if( IsKeyPressed(VK_LEFT) ) myKeys[ARROW_LEFT] = true; if( IsKeyPressed(VK_RIGHT) ) myKeys[ARROW_RIGHT] = true; /** Scrolling **/ GLFWwindow* glfwGetCurrentContext(void); glfwSetScrollCallback(glfwGetCurrentContext(), scroll); if(scrollyPos > 0.0) { myKeys[SCROLL_UP] = true; } else if(scrollyPos < 0.0) { myKeys[SCROLL_DOWN] = true; } if(scrollyPos != 0.0) { scrollyPos = 0.0; } }
virtual KeyAction CheckKey(int key) { #ifdef MFLD_PRX_KEY_LAYOUT if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) { #else if (IsKeyPressed(KEY_VOLUMEDOWN) && key == KEY_VOLUMEUP) { #endif return TOGGLE; } return ENQUEUE; } };
// Update game (one frame) void UpdateGame(void) { if (!gameOver) { if (IsKeyPressed('P')) pause = !pause; if (!pause) { // Player movement if (IsKeyDown(KEY_LEFT)) player.position.x -= 5; if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2; if (IsKeyDown(KEY_RIGHT)) player.position.x += 5; if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2; // Launch ball if (!ball.active) { if (IsKeyPressed(KEY_SPACE)) { ball.active = true; ball.speed = (Vector2){ 0, -5 }; } } UpdateBall(); // Game over logic if (player.life <= 0) gameOver = true; else { gameOver = true; for (int i = 0; i < LINES_OF_BRICKS; i++) { for (int j = 0; j < BRICKS_PER_LINE; j++) { if (brick[i][j].active) gameOver = false; } } } } } else { if (IsKeyPressed(KEY_ENTER)) { InitGame(); gameOver = false; } } }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [audio] example - sound loading and playing"); InitAudioDevice(); // Initialize audio device Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (IsKeyPressed(KEY_SPACE)) PlaySound(fxWav); // Play WAV sound if (IsKeyPressed(KEY_ENTER)) PlaySound(fxOgg); // Play OGG sound //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); DrawText("Press SPACE to PLAY the WAV sound!", 200, 180, 20, LIGHTGRAY); DrawText("Press ENTER to PLAY the OGG sound!", 200, 220, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadSound(fxWav); // Unload sound data UnloadSound(fxOgg); // Unload sound data CloseAudioDevice(); // Close audio device CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int GameOver(int player) { //MOKHTAR,HAITHAM,BRAHIM,SALAH,WASSIM int FallIndexes[5]= {29,23,47,29,26},selection=0, button_pressed=0;; IMAGE **Pics; IMAGE*cadre=load_image("Resources/Images/ingame_bar.png"); switch(player) { case 0: Pics=MokhtarPics; break; case 1: Pics=HaithamPics; break; case 2: Pics=BrahimPics; break; case 3: Pics=SalahPics; break; case 4: Pics=WassimPics; break; } while(!IsKeyPressed(1,ENTER)) { button_pressed++; if((IsKeyPressed(1,LEFT) || IsKeyPressed(1,RIGHT)) && button_pressed>10) { selection=!selection; button_pressed=0; } draw_text(SharpCurve,"Game Over",20,50,5,CENTER_X,100); draw_text(Arista,"Continue?",8,50,30,CENTER_X,100); draw_text(Arista,"YES",8,25,50,CENTER_X,100); draw_text(Arista,"NO",8,75,50,CENTER_X,100); draw_image_ex(Pics[FallIndexes[player]],25,30,50,0,NONE,100); draw_image_ex(cadre,18+selection*50,40,15,30,NONE,100); next_frame(); } while(IsKeyPressed(1,ENTER)) rest(1); return !selection; }
// The default CheckKey implementation assumes the device has power, // volume up, and volume down keys. // // - Hold power and press vol-up to toggle display. // - Press power seven times in a row to reboot. // - Alternate vol-up and vol-down seven times to mount /system. RecoveryUI::KeyAction RecoveryUI::CheckKey(int key) { if (IsKeyPressed(KEY_POWER) && key == KEY_VOLUMEUP) { return TOGGLE; } if (key == KEY_POWER) { ++consecutive_power_keys; if (consecutive_power_keys >= 7) { return REBOOT; } } else { consecutive_power_keys = 0; } if ((key == KEY_VOLUMEUP && (last_key == KEY_VOLUMEDOWN || last_key == -1)) || (key == KEY_VOLUMEDOWN && (last_key == KEY_VOLUMEUP || last_key == -1))) { ++consecutive_alternate_keys; if (consecutive_alternate_keys >= 7) { consecutive_alternate_keys = 0; return MOUNT_SYSTEM; } } else { consecutive_alternate_keys = 0; } last_key = key; return ENQUEUE; }
void InputManager::UpdateVirtualButtons() { bool pressed; for (int i=0; i<(int)_myVirtualButtons.Size();i++) { pressed = IsKeyPressed(_myVirtualButtons[i].button); _myVirtualButtons[i].keyDown=_myVirtualButtons[i].keyUp=false; if (!_myVirtualButtons[i].keyPress && pressed) { _myVirtualButtons[i].keyDown=true; EventManager::Instance().CallbackVButton(_myVirtualButtons[i].name, Event::buttonDown); } else if (_myVirtualButtons[i].keyPress && !pressed) { _myVirtualButtons[i].keyUp=true; EventManager::Instance().CallbackVButton(_myVirtualButtons[i].name,Event::buttonUp); } _myVirtualButtons[i].keyPress = pressed; /*if (pressed) EventManager::Instance().CallbackVButton(_myVirtualButtons[i].name, static_cast<int>(EventVButton::buttonPressed));*/ } }
BOOL InputClient_State::IsAltPressed() const { return IsKeyPressed(EKeyCode::Key_Menu) //|| IsKeyPressed(EKeyCode::Key_LMenu) //|| IsKeyPressed(EKeyCode::Key_RMenu) ; }
BOOL InputClient_State::IsCtrlPressed() const { return IsKeyPressed(EKeyCode::Key_Control) //|| IsKeyPressed(EKeyCode::Key_LControl) //|| IsKeyPressed(EKeyCode::Key_RControl) ; }
BOOL InputClient_State::IsShiftPressed() const { return IsKeyPressed(EKeyCode::Key_Shift) //|| IsKeyPressed(EKeyCode::Key_LShift) //|| IsKeyPressed(EKeyCode::Key_RShift) ; }
void Common_Update() { /* Capture key input */ unsigned int newButtons = 0; while (IsKeyPressed()) { unsigned int key = getchar(); if (key == '1') newButtons |= (1 << BTN_ACTION1); else if (key == '2') newButtons |= (1 << BTN_ACTION2); else if (key == '3') newButtons |= (1 << BTN_ACTION3); else if (key == '4') newButtons |= (1 << BTN_ACTION4); else if (key == 'h') newButtons |= (1 << BTN_LEFT); else if (key == 'l') newButtons |= (1 << BTN_RIGHT); else if (key == 'k') newButtons |= (1 << BTN_UP); else if (key == 'j') newButtons |= (1 << BTN_DOWN); else if (key == 32) newButtons |= (1 << BTN_MORE); else if (key == 'q') newButtons |= (1 << BTN_QUIT); } gPressedButtons = (gDownButtons ^ newButtons) & newButtons; gDownButtons = newButtons; /* Update the screen */ printf("%c[H", 0x1B); // Move cursor to home position printf("%s", gConsoleText.c_str()); // Terminal console is already double buffered, so just print printf("%c[J", 0x1B); // Clear the rest of the screen gConsoleText.clear(); }
void Input::OnKeyPressedMsgApply(KeyboardKey key) { if (IsKeyDown(key) || IsKeyPressed(key)) return; mPressedKeys.Add(key); }
char CInputManager::GetChar(bool enableShift, bool enableCapslock) const { BYTE input[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', 0xc0, 0xbd, 0xbb, 0xdc, 0xdb, 0xdd, 0xba, 0xde, 0xbc, 0xbe, 0xbf, ' ', 0x0d, '\t', '\b' }; BYTE output[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '`', '-', '=', '\\', '[', ']', ';', '\'', ',', '.', '/', ' ', '\n', '\t', '\b' }; BYTE output2[] = { ')', '!', '@', '#', '$', '%', '^', '&', '*', '(', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '~', '_', '+', '|', '{', '}', ':', '\"', '<', '>', '?', ' ', '\n', '\t', '\b' }; // from combination of capslock and shit, figure out what is the case char mod = (enableShift && IsKeyDown(Keys::Shift)) + (enableCapslock && IsCapslockActive()); for (int i = 0; i < sizeof(input); i++) { if (IsKeyPressed((Keys)input[i])) { if (mod == 1) return output2[i]; else return output[i]; } } return 0; }
// Mission Screen Update logic void UpdateMissionScreen(void) { UpdateMusicStream(musMission); if (!writeEnd) WriteMissionText(); else { framesCounter++; if ((framesCounter%blinkFrames) == 0) { framesCounter = 0; blinkKeyWord = !blinkKeyWord; } } if (showButton) { if (IsKeyPressed(KEY_ENTER) || IsButtonPressed()) { if (!writeEnd) { writeEnd = true; writeKeyword = true; writeNumber = true; missionLenght = missionMaxLength; } else { finishScreen = true; showButton = false; } } } }
// Gameplay Screen Update logic void UpdateGameplayScreen(void) { if (IsKeyPressed('P')) { pause = !pause; if (!pause) ResumeMusicStream(); else PauseMusicStream(); } if (!pause) { if (!startGame && IsKeyPressed(KEY_SPACE)) { startGame = TRUE; ResumeMusicStream(); } // TODO: Update GAMEPLAY screen variables here! if (startGame) { UpdateMainCamera(&mainCamera); UpdateTrianglesPosition(mainCamera.position); UpdateTrianglesState(); UpdatePlatformsPosition(mainCamera.position); UpdatePlatformsState(); UpdatePlayer(&player); } } // Press enter to change to ENDING screen /* if (IsKeyPressed(KEY_ENTER) || !player.isAlive || mainCamera.position.x/CELL_SIZE>GRID_WIDTH+10) { finishScreen = 1; } */ // WIN / LOSE Conditions if (!player.isAlive) GameplayEnd(1); // If player dies, reset gameplay screen else if (mainCamera.position.x/CELL_SIZE>GRID_WIDTH+20) GameplayEnd(2); // If player reaches the end level (+20 cells) game ends. // MusicIsPlaying UpdateMusicStream(); }
virtual KeyAction CheckKey(int key) { switch (key) { case KEY_VOLUMEUP: case KEY_UP: if (IsKeyPressed(KEY_VOLUMEDOWN) || IsKeyPressed(KEY_VOLUMEUP)) return TOGGLE; break; case KEY_VOLUMEDOWN: case KEY_DOWN: if (IsKeyPressed(KEY_VOLUMEUP) || IsKeyPressed(KEY_UP)) return TOGGLE; break; case KEY_ESC: return TOGGLE; } return ENQUEUE; }
//if the passed-in key is initially pressed in this frame, will return true bool InputManager::IsKeyTriggered(InputKey key) { //if the key wasn't pressed in the previous frame, but is in this frame if (!(prev_keyboardState[keyMap[key]] && 0x80) && IsKeyPressed(key)) return true; else return false; }
const TEXTCHAR* GetKeyText (int key) { int used = 0; CTEXTSTR result = SACK_Vidlib_GetKeyText( IsKeyPressed( key ), KEY_CODE( key ), &used ); if( used ) return result; return 0; }
bool InputObject::IsKeyReleased(unsigned int key) { if (key >= INPUTOBJECT_KEYBOARD_MAX) throw std::exception("Keyboard key index out of bounds"); if (IsFocused() || GetFocus()==m_hwnd) return (IsPrevKeyPressed(key) && !IsKeyPressed(key)) != 0; return false; }
//if the passed-in key was released this frame, will return true bool InputManager::IsKeyReleased(InputKey key) { //if the key was pressed in the previous frame, but not in this frame if ((prev_keyboardState[keyMap[key]] && 0x80) && !IsKeyPressed(key)) return true; else return false; }
bool Input::IsKeyMaskPressed(const std::string& mask) { for (std::list<KeyCode>::iterator i = instance->keyMasks[mask].begin(); i != instance->keyMasks[mask].end(); ++i) { if (IsKeyPressed(*i)) return true; } return false; }
void CameraControllerBase::HandleInput( const InputData& input ) { switch( input.iGICode ) { case GIC_MOUSE_BUTTON_L: case GIC_MOUSE_BUTTON_R: if( input.iType == ITYPE_KEY_PRESSED ) { switch( input.iGICode ) { case GIC_MOUSE_BUTTON_L: m_IsMouseButtonPressed[MBTN_LEFT] = 1; break; case GIC_MOUSE_BUTTON_R: m_IsMouseButtonPressed[MBTN_RIGHT] = 1; break; default: break; } } else if( input.iType == ITYPE_KEY_RELEASED ) { switch( input.iGICode ) { case GIC_MOUSE_BUTTON_L: m_IsMouseButtonPressed[MBTN_LEFT] = 0; break; case GIC_MOUSE_BUTTON_R: m_IsMouseButtonPressed[MBTN_RIGHT] = 0; break; default: break; } } break; case GIC_MOUSE_AXIS_X: if( IsKeyPressed( GIC_MOUSE_BUTTON_R ) ) AddYaw( input.fParam1 / 500.0f ); // rotation else if( IsKeyPressed( GIC_MOUSE_BUTTON_L ) ) Move( input.fParam1 / 200.0f, 0.0f, 0.0f ); // translation break; case GIC_MOUSE_AXIS_Y: if( IsKeyPressed( GIC_MOUSE_BUTTON_R ) ) AddPitch( input.fParam1 / 500.0f * (-1.0f) ); // rotation else if( IsKeyPressed( GIC_MOUSE_BUTTON_L ) ) Move( 0.0f, input.fParam1 / 200.0f, 0.0f ); // translation break; default: break; } }
void MouseDown(TMouseButton button) { #ifndef USESENDINPUT if(button==mbLeft) { mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); } else if(button==mbRight) { mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0); } else if(button==mbMiddle) { mouse_event(MOUSEEVENTF_MIDDLEDOWN,0,0,0,0); } #else INPUT input; ::ZeroMemory(&input, sizeof(input)); if(button==mbLeft) { if(IsKeyPressed(VK_LBUTTON)) return; input.type = INPUT_MOUSE; input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN; ::SendInput(1,&input,sizeof(INPUT)); } else if(button==mbRight) { if(IsKeyPressed(VK_RBUTTON)) return; input.type = INPUT_MOUSE; input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN; ::SendInput(1,&input,sizeof(INPUT)); } else if(button==mbMiddle) { if(IsKeyPressed(VK_MBUTTON)) return; input.type = INPUT_MOUSE; input.mi.dwFlags = MOUSEEVENTF_MIDDLEDOWN; ::SendInput(1,&input,sizeof(INPUT)); } #endif // if(sleepsec) Sleep(sleepsec); }