Hello everyone ,
So I am currently working on a project, it requires me to use only console and get the keyboard inputs in real time.
That implies that I have to handle keyboard inputs but I don't have any window to do it.
The code is below now it compiles and all however I have a big problem whenever I press a key it counts as multiple keypresses.
(20 at least) obviously that's a big problem. I've looked around and saw the keyRepeatEnabled function however this requires a window that I don't want to use.
I hope to have been clear on my problem and you'll be able to bring a solution. How to get only one key press instead of multiple ones.
Best Regards,
void Player::player_mvt(Board &board) {
while (!(sf::Keyboard::isKeyPressed(sf::Keyboard::Return) && board.getBoard(board.getBase().first,
board.getBase().second).isTarget())) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
handle_mvt(board, std::make_pair(0, -1));
break;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) {
handle_mvt(board, std::make_pair(-1, 0));
break;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard:
)) {
handle_mvt(board, std::make_pair(0, 1));
break;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
handle_mvt(board, std::make_pair(1, 0));
break;
} else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) {
std::cout << "Cannot move in this position" << std::endl;
}
}
}