Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - tobiasrj

Pages: [1]
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

#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));
    }
}
 

Pages: [1]