#include <iostream>
#include <SFML/Window/Keyboard.hpp>
int main(int argc, constchar* argv[])
{
constint MAX_KEYS = 4;
bool keyPressed[MAX_KEYS];
enum keys
{
left,
right,
up,
down
};
for (int i = 0; i < MAX_KEYS; ++i)
{
keyPressed[i] = false;
}
while (1)
{
/* For each key, I'll use left as an example */
if(Keyboard::isKeyPressed(Keyboard::Left))
{
if (!keyPressed[left])
{
std::cout << "Left Key pressed\n";
keyPressed[left] = true;
}
}
else
{
keyPressed[left] = false;
}
}
}
Quick untested example as I'm at work an on my lunch break. There's definitely a more elegant way to do this, too. For example, you could map the keys to bools an iterate over the keys in the map. That way, you wouldn't need to write out a case for each key.
many tnx @iHutch105, it worked !!, tnx also @CodeGazer, i didn't knew that method exists, although i'm only testing this in the console, i can possibly use that method for a future project