Jump to content
  • Advertisement
akshayMore

SFML : multiple key issue

Recommended Posts

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.  

 

Share this post


Link to post
Share on other sites
Advertisement

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/

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!