In this section, we are going to learn how to handle input devices such as a keyboard, mouse or touch, and Xbox controllers. Let's start the integration of our framework with the keyboard, the old friend of gamers.
Open the Inputs
project from the source code and then open the KeyboardState.cpp
class from the FrameWork/Input
folder. The KeyboardState.cpp
class has the following code:
bool KeyboardState::IsKeyDown(VirtualKey key) { return keys[key] == true; } bool KeyboardState::IsKeyUp(VirtualKey key) { return keys[key] == false; } void KeyboardState::SaveKeyState(VirtualKey key, bool IsPressed) { keys[key] = IsPressed; } void KeyboardState::ClearBuffer() { for (auto k : this->keys) { k.second = false; } } void KeyboardState::Unload() { keys.clear(); }
The preceding methods simply store the states of the keys. When the keys are pressed or released, the SaveKeyState
method stores the keys' states as Boolean values. The IsKeyDown
and IsKeyUp
...