16
General / Strange behavior with isKeyPressed() function
« on: July 11, 2015, 09:21:08 am »
Hi,
I'm using isKeyPressed function for smooth movement.
it works correctly when I'm using up/down/left/right with shift.
But when I use numpad, the problem comes up.
First, if I press shift and then numpad, it doesn't catch shift.
and when I press numpad first and then shift (while pressing numpad),
isKeyPressed(numpad) returns always true after I released the key. (not always but very often)
also in this situation, even if I turn the program off and on, the isKeyPressed function still returns true.
Here's a small example of the code. (I'm using windows 8.1 and vs2013)
while (window.isOpen())
{
bool shift = sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift);
bool up = sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad8);
bool down = sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad2);
bool left = sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad4);
bool right = sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad6);
std::string string = "";
if (shift)
string += "shift ";
if (up)
string += "up";
if (down)
string += "down";
if (left)
string += "left";
if (right)
string += "right";
text.setString(string);
window.clear();
window.draw(text);
window.display();
}
I always very appreciate to SFML team, Thanks
Edit: fixed typos
I'm using isKeyPressed function for smooth movement.
it works correctly when I'm using up/down/left/right with shift.
But when I use numpad, the problem comes up.
First, if I press shift and then numpad, it doesn't catch shift.
and when I press numpad first and then shift (while pressing numpad),
isKeyPressed(numpad) returns always true after I released the key. (not always but very often)
also in this situation, even if I turn the program off and on, the isKeyPressed function still returns true.
Here's a small example of the code. (I'm using windows 8.1 and vs2013)
while (window.isOpen())
{
bool shift = sf::Keyboard::isKeyPressed(sf::Keyboard::LShift) || sf::Keyboard::isKeyPressed(sf::Keyboard::RShift);
bool up = sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad8);
bool down = sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad2);
bool left = sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad4);
bool right = sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::Numpad6);
std::string string = "";
if (shift)
string += "shift ";
if (up)
string += "up";
if (down)
string += "down";
if (left)
string += "left";
if (right)
string += "right";
text.setString(string);
window.clear();
window.draw(text);
window.display();
}
I always very appreciate to SFML team, Thanks
Edit: fixed typos