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

Author Topic: Keyboard input behaves strange  (Read 1006 times)

0 Members and 1 Guest are viewing this topic.

tobiasrj

  • Newbie
  • *
  • Posts: 1
    • View Profile
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));
    }
}
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Keyboard input behaves strange
« Reply #1 on: November 14, 2016, 09:14:36 pm »
What OS? What terminal?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/