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

Author Topic: Mouse and keyboard at the same time  (Read 2125 times)

0 Members and 1 Guest are viewing this topic.

Nemecis

  • Newbie
  • *
  • Posts: 5
    • View Profile
Mouse and keyboard at the same time
« on: August 23, 2014, 11:53:54 pm »
I have this outside event loop:

if(sf::Mouse::isButtonPressed(sf::Mouse::Button::Left)){
                                shotInitialize(player);
                }

                //Reasons for keycodes are in fhe function movePlayer
                keyPress = 0;
                                if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
                                        keyPress = keyPress + 1;
                                }
                                if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
                                        keyPress = keyPress + 2;
                                }
                                if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
                                        keyPress = keyPress + 8;
                                }
                                if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
                                        keyPress = keyPress + 4;
                                }


                       
               
                //Clear previous render
                window.clear();

                movePlayer(player, keyPress);
                shotUpdate(player, window, spriteContainer);
                spriteContainer.Player.setPosition(player.positionX, player.positionY);
                spriteContainer.Player.setRotation(player.rotation);
                window.draw(spriteContainer.Player);


                //Display new render
        window.display();

But for some reason, when mouse button is pressed while, or right after keyboard button is pressed, it won't do anything. This is quite annoying, since this prohibits real time input. Could someone tell me how could I make keyboard states not interfere with mouse buttons etc?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Mouse and keyboard at the same time
« Reply #1 on: August 24, 2014, 12:11:14 am »
I don't know of any reason why mouse and keyboard states would interfere with each other, so it's probably a bug in your code.  Unfortunately the code in your post is incomplete, so the bug is probably in some part of the code that you haven't shown us.  If you could show us a complete and minimal example that has this problem, then we can help you.

Also, your description is a bit too vague.  What does "it won't do anything" mean?  Does the program stop responding to user input but keep running?  All user input or only some kinds?  Does it freeze completely?  And "when mouse button is pressed while" is grammatically incorrect so I can't tell what that means.

Nemecis

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mouse and keyboard at the same time
« Reply #2 on: August 24, 2014, 12:26:04 am »
Sorry for vague description. So when I press keyboard button, mouse button state is always false. If I press mouse button, and then keyboard button, both are true and work normally. Also, if I press keyboard button, then release it, and right after releasing the button press mouse button, mouse button doesn't trigger until around 1sec has passed from releasing keyboard button.

Here is the most minimal code, that will reproduce the problem:
#include <iostream>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Keyboard.hpp>


int main()
{
        while (true)
    {

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
                        std::cout <<"KB\n";    
                }

                if(sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                                std::cout << "MB\n";
                }
                       
        }
       
        return 0;
}

 

In the code, keyboard button w and LMB are used.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Mouse and keyboard at the same time
« Reply #3 on: August 24, 2014, 12:30:59 am »
Wow, that is bizarre.  Now it sounds like a hardware or driver problem.  Do you experience a similar problem on your computer with games that have mouse and keyboard controls?  Does this happen on any other computers you have access to?  What is your hardware and are its drivers up to date?

Also I think this is in the wrong forum.  Hopefully someone with move permissions sees this.

Nemecis

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Mouse and keyboard at the same time
« Reply #4 on: August 24, 2014, 12:39:16 am »
I haven't tested other systems, but same bug was with windows' getAsyncKeyState, so hardware is probably problem. I'm using ASUS G750JX, win8 and latest drivers. I'll test with a hardware mouse soon, as this could be a trackpad button bug.

E: Yup, It's HW/Driver bug. Plugging in external mouse solved issue.
« Last Edit: August 24, 2014, 12:46:57 am by Nemecis »

 

anything