2021-09-19 15:44:31 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 19.09.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Keyboard.h"
|
|
|
|
#include "utils/Time.h"
|
2021-10-16 20:22:55 +03:00
|
|
|
#include "Consts.h"
|
2021-09-19 15:44:31 +03:00
|
|
|
|
|
|
|
bool Keyboard::isKeyPressed(sf::Keyboard::Key key) {
|
|
|
|
return sf::Keyboard::isKeyPressed(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Keyboard::isKeyTapped(sf::Keyboard::Key key) {
|
2021-10-28 16:58:02 +03:00
|
|
|
if (!Keyboard::isKeyPressed(key)) {
|
2021-09-19 15:44:31 +03:00
|
|
|
return false;
|
2021-10-28 16:58:02 +03:00
|
|
|
}
|
2021-09-19 15:44:31 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
if (_tappedKeys.count(key) == 0) {
|
2021-09-19 15:44:31 +03:00
|
|
|
_tappedKeys.emplace(key, Time::time());
|
|
|
|
return true;
|
2021-10-31 11:39:08 +03:00
|
|
|
} else if ((Time::time() - _tappedKeys[key]) > Consts::TAP_DELAY) {
|
2021-09-19 15:44:31 +03:00
|
|
|
_tappedKeys[key] = Time::time();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|