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

Author Topic: Input bug when holding shift?  (Read 2807 times)

0 Members and 1 Guest are viewing this topic.

XenoZergNid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Input bug when holding shift?
« on: January 09, 2016, 08:30:27 pm »
I created a program to demonstrate my problem below. To replicate hold down A, then hold down shift. Release A, then release shift. The program now prints that A is held down even though A was released. One can do the same with D.

#include <SFML/Graphics.hpp>
#include <iostream>


int main()
{
        // Create the main window
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");


        bool ADown = false;
        bool DDown = false;

        // Start the game loop
        while (window.isOpen())
        {
                // Process events
                sf::Event event;
                while (window.pollEvent(event))
                {
                        // Close window: exit
                        if (event.type == sf::Event::Closed)
                                window.close();

       
                        if (event.type == sf::Event::KeyPressed) {
                                if(event.key.code == sf::Keyboard::Key::A)
                                        ADown = true;
                                else if(event.key.code == sf::Keyboard::Key::D)
                                        DDown = true;
                        }
                        else if (event.type == sf::Event::KeyReleased) {
                                if(event.key.code == sf::Keyboard::Key::A)
                                        ADown = false;
                                else if(event.key.code == sf::Keyboard::Key::D)
                                        DDown = false;
                        }
                }

                std::cout << "A: " << ADown << ", D: " << DDown << "\n";


                // Clear screen
                window.clear();


                // Update the window
                window.display();
        }





        return EXIT_SUCCESS;
}
 

I run archlinux and sfml 2.3.2
Thanks in advance.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Input bug when holding shift?
« Reply #1 on: January 09, 2016, 08:44:25 pm »
I cannot replicate your behaviour with this code.

Windows, SFML 2.3.2 : 32-bit - debug & release, static & dynamic.

Does ADown turn true on the release of the shift or is it constantly true after pressing shift?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

XenoZergNid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Input bug when holding shift?
« Reply #2 on: January 10, 2016, 06:36:37 am »
@Hapax

ADown becomes true when I press A, then continues to be true while holding shift then still remains true after A is released and still doesn't change after a release the shift key.

Is it possible that it could be something wrong with my system? I haven't had any problems with input anywhere else.

I used the following command: g++ -std=c++14 -g3 ./main.cpp -o ./test -lsfml-graphics -lsfml-window -lsfml-system

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: Input bug when holding shift?
« Reply #3 on: January 10, 2016, 12:28:48 pm »
Does it work with this version of SFML ? (contains a fix that allow keys to be detected with a modifier is pressed on Linux) : https://github.com/SFML/SFML/tree/bugfix/unix_keyevents

XenoZergNid

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Input bug when holding shift?
« Reply #4 on: January 10, 2016, 10:03:54 pm »
@victorlevasseur

Thank you very much. It works beautifully.

I'm knew to these forums so just tell me if I'm supposed to close it somehow.