Files
mcpe/source/client/player/input/Keyboard.cpp
Brent f7915a1dab Mac OS X 10.6 & More C++03 Support (#68)
* Mac OS X 10.6 & More C++03 Support

* Fix SDL2 options.txt loading for C++03

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
2023-08-27 11:46:15 +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] == DOWN;
}
void Keyboard::reset()
{
_inputs.clear();
_index = -1;
}