SFML community forums

Help => Window => Topic started by: thatoneguy on August 03, 2013, 09:03:38 am

Title: [Solved] Issue with sf::Keyboard::isPressed
Post by: thatoneguy on August 03, 2013, 09:03:38 am
Hello I've recently been learning to use multiple threads and using sf::Keyboard for unbuffered input. The issue I'm running into is that when I press A with the following code it doesn't run the what's within the if block.
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) { // Returns false
        message_out += "a";
        std::cout << "WORKED";
}
 

But when trying this it works properly and prints "WORKED"
bool test = sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A); // Returns true
    if (test == true) {
        message_out += "a";
                std::cout << "WORKED";
    }
 

Is this an issue with threads or a bug?
Title: Re: Issue with sf::Keyboard::isPressed
Post by: eXpl0it3r on August 03, 2013, 09:16:45 am
You're doing most likely somewhere else something wrong. Can you provide a minimal and complete example that reproduces the problem?
Also SFML is not a thread safe library, so you'll have to make sure, that the resources are shared properly!

In most cases you don't need threads at all. From what exactly are you trying to use it?
Title: Re: Issue with sf::Keyboard::isPressed
Post by: thatoneguy on August 03, 2013, 10:33:52 am
It wasn't working for the life of me earlier, but after clearing my mind playing TF2 and restarting Visual Studio it worked.

I'm working on a TCP server/client chat. I've just been reading the documentation and examples, so I have a rough approach. I have a thread each for sending information and receiving information because when I was reading input it would wait on cin.