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?
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.