Comments (1)
class KeyboardState {
private:
bool pressed, held, released, oldState;
public:
bool IsPressed();
bool IsHeld();
bool IsReleased();
void KeyDown();
void KeyUp();
};
KeyboardState keyboard[256];
bool KeyboardState::IsPressed() {
bool val = pressed;
pressed = false;
return val;
}
bool KeyboardState::IsHeld() {
return held;
}
bool KeyboardState::IsReleased() {
bool val = released;
released = false;
return val;
}
void KeyboardState::KeyDown() {
pressed = released = false;
if (!oldState) {
pressed = !held;
held = true;
}
oldState = true;
}
void KeyboardState::KeyUp() {
pressed = released = false;
if (oldState) {
released = true;
held = false;
}
oldState = false;
}
// In windows management events:
case WM_KEYDOWN:
key = mapKeys[(const unsigned short)wParam];
keyboard[key].KeyDown();
return 0;
case WM_KEYUP:
key = mapKeys[(const unsigned short)wParam];
keyboard[key].KeyUp();
return 0;
// To use it just do
bool isAHeld =keybard[Key::A].IsHeld();
bool isAReleased =keybard[Key::A].IsReleased();
Be aware that IsPressed() and IsHeld() will reset the value, so the cycle to reset all keys on each frame is no more needed.
from olcpixelgameengine.
Related Issues (20)
- Doesn't build with /Wx and /Wall
- Directly draw on a sprite --> scaled string HOT 2
- Implement PingPong style in Animate2D HOT 1
- olcUTIL_Camera2D: m_vScreenSize is hard coded with no construction update, or means to change
- WASM (Emscripten): font looks ugly (strange underscores) HOT 2
- drawing Decal on Decal --> no transparency possible? HOT 2
- cursor disable and mouse delta values HOT 1
- Not an issue - Font suggestions. HOT 3
- PGEX extensions not usable in dll context
- TEST_Animate2D.cpp does not compile on ubuntu HOT 9
- Integrating render window into MFC or Qt
- have no function loading like mutillang font file or vector diagram as pixel Sprite HOT 1
- ModalDialog doesn't function intended
- olc::QuickGui::TextBox focusing issue
- broken link to RetroMenu.png asset in olcPGEX_PopUpMenu.h
- Support request: how can i port this library to embedded systems? HOT 8
- Multithreading in Visual Studio compiled program HOT 2
- Something causing dataraces? HOT 4
- PixelGameEngine::Construct() not defined for Ubuntu HOT 2
- Decals don't work if not constructed in PixelGameEngine class HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from olcpixelgameengine.