1
General / Keyboard input behaves strange
« on: November 14, 2016, 07:25:52 pm »
Can anyone explain why the code below output something like this, when pressing right and left arrow key?
Output:
^[[DLeft
^[[C^[[C^[[CRight
^[[D^[[DLeft
^[[D^[[DLeft
^[[C^[[C^[[CRight
Output:
^[[DLeft
^[[C^[[C^[[CRight
^[[D^[[DLeft
^[[D^[[DLeft
^[[C^[[C^[[CRight
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
int main(int argc, char** argv)
{
while(1)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
cout << "Left" << endl;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
cout << "Right" << endl;
}
sf::sleep(sf::milliseconds(1000));
}
}
#include <SFML/Graphics.hpp>
using namespace std;
int main(int argc, char** argv)
{
while(1)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
cout << "Left" << endl;
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
cout << "Right" << endl;
}
sf::sleep(sf::milliseconds(1000));
}
}