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

Author Topic: [Solved] Issue with sf::Keyboard::isPressed  (Read 2007 times)

0 Members and 1 Guest are viewing this topic.

thatoneguy

  • Newbie
  • *
  • Posts: 25
    • View Profile
[Solved] Issue with sf::Keyboard::isPressed
« 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?
« Last Edit: August 03, 2013, 10:34:11 am by thatoneguy »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Issue with sf::Keyboard::isPressed
« Reply #1 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

thatoneguy

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Issue with sf::Keyboard::isPressed
« Reply #2 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.