Advertisement

SFML : multiple key issue

Started by May 15, 2019 02:40 PM
1 comment, last by Rutin 5 years, 9 months ago

SFML : multiple key issue

           if (Keyboard::isKeyPressed(Keyboard::Space))
            {
                std::cout << "Space" << std::endl;
            }

            if (Keyboard::isKeyPressed(Keyboard::Left))
            {
                std::cout << "Left" << std::endl;
            }

            if (Keyboard::isKeyPressed(Keyboard::Right))
            {
                std::cout << "Right" << std::endl;
            }

            if (Keyboard::isKeyPressed(Keyboard::Up))
            {
                std::cout << "Up" << std::endl;
            }

output:

CASE 1:

1) When pressed Up + Left + Space :

Up

Left

Space

2) When Pressed Up + Right + Space :

Up

Right 

After searching for a while I found out that most keyboards can only only register a certain number of key presses at any given time, and ignore any subsequent key presses until you release one or more of the current keys. This doesn't apply to modifier keys (like Ctrl, alt, and shift) . So I checked it by replacing "Space" key by with "LAlt". The output was :

CASE 2:

1) When pressed Up + Left + LAlt :

Up

Left

LAlt 

2) When Pressed Up + Right + LAlt :

Up

Right 

LAlt

This works as expected but........if keyboards can only only register a certain number of key presses at any given time

then why was "space" key detected when pressed along with "up" and "left" key and not with "up" and "right" key? 

Is this an issue with sfml?  I just want to confirm whether it is indeed the issue where keyboard is unable to register multiple key press at same time. 

I am trying to fire bullets from a spaceship. I am able to shoot bullets while moving forward and steering left but unable to shoot while steering right. I would really appreciate any help.  

 

This has zero to do with SFML but a limitation with the keyboards themselves. I personally have a mechanical keyboard which eliminates this problem, and some people will buy "Gaming Keyboards" which prevent this up to (x) presses. The best way to be sure it is not SFML is to do these tests through other applications:

http://keyboardchecker.com/

Programmer and 3D Artist

This topic is closed to new replies.

Advertisement