Files
mcpe/source/client/player/input/Keyboard.cpp
Brent Da Mage d5ee7bfc08 Cleaned Up AppPlatform & Input Classes
* Cleaned up AppPlatform classes
* Documented & improved Keyboard & Mouse classes
* Improved input-handling code in the Windows & SDL main.cpp files
2023-08-19 15:57:50 +03:00

63 lines
1.2 KiB
C++

/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "Keyboard.hpp"
#include "GameMods.hpp"
std::vector<KeyboardAction> Keyboard::_inputs;
int Keyboard::_index = -1;
Keyboard::KeyState Keyboard::_states[KEYBOARD_STATES_SIZE];
void Keyboard::feed(KeyState state, int key)
{
#ifndef ORIGINAL_CODE
// Prevent Crashes
if (key >= KEYBOARD_STATES_SIZE || key < 0) {
return;
}
#endif
_inputs.push_back(KeyboardAction(key, state));
_states[key] = state;
}
bool Keyboard::next()
{
if (_index + 1 >= _inputs.size())
return false;
_index++;
return true;
}
int Keyboard::getEventKey()
{
return _inputs[_index]._keyCode;
}
int Keyboard::getEventKeyState()
{
return _inputs[_index]._keyState;
}
bool Keyboard::isKeyDown(int keyCode)
{
if (keyCode < 0 || keyCode >= KEYBOARD_STATES_SIZE)
return false;
return _states[keyCode] == KeyState::DOWN;
}
void Keyboard::reset()
{
_inputs.clear();
_index = -1;
}