SFML pollEvent is making pauses when I continuesly press Keys












1















Apparently my pollEvent is making some little pause when I continuously press a Key,



For example if a press and don't release a Key, it's calling the press event, BUT THEN is making a little pause of 0.5sec and only after that starts to call continuously the press Event
So simply put, if I just press a Key and don't release it, it gives me an output like that:



press A



pause



press A



press A



press A



press A



. . .



It's kinda problematic for my game.
my pollEvent loop:



std::map<_KEYS, bool>   Display::checkEvents()
{
resetEvents();
while (_Window.pollEvent(_Event))
{
if (_Event.type == sf::Event::Closed)
quit();
if (_Event.type == sf::Event::KeyPressed) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
puts("key up pressed");
_Events.at(_KEY_UP) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
puts("key down pressed");
_Events.at(_KEY_DOWN) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
puts("key left pressed");
_Events.at(_KEY_LEFT ) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
puts("key right pressed");
_Events.at(_KEY_RIGHT) = true;
}
}
return (_Events);
}


Any idea why ? or how I can resolve this problem ?



PS: don't mind my Event map, I think it's really far from being related with the pauses










share|improve this question























  • Writing to the console takes ages. Maybe those puts() calls could be causing it?

    – Galik
    Nov 20 '18 at 23:55













  • I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

    – VK_
    Nov 21 '18 at 11:11






  • 1





    That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

    – Rosme
    Nov 21 '18 at 15:08
















1















Apparently my pollEvent is making some little pause when I continuously press a Key,



For example if a press and don't release a Key, it's calling the press event, BUT THEN is making a little pause of 0.5sec and only after that starts to call continuously the press Event
So simply put, if I just press a Key and don't release it, it gives me an output like that:



press A



pause



press A



press A



press A



press A



. . .



It's kinda problematic for my game.
my pollEvent loop:



std::map<_KEYS, bool>   Display::checkEvents()
{
resetEvents();
while (_Window.pollEvent(_Event))
{
if (_Event.type == sf::Event::Closed)
quit();
if (_Event.type == sf::Event::KeyPressed) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
puts("key up pressed");
_Events.at(_KEY_UP) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
puts("key down pressed");
_Events.at(_KEY_DOWN) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
puts("key left pressed");
_Events.at(_KEY_LEFT ) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
puts("key right pressed");
_Events.at(_KEY_RIGHT) = true;
}
}
return (_Events);
}


Any idea why ? or how I can resolve this problem ?



PS: don't mind my Event map, I think it's really far from being related with the pauses










share|improve this question























  • Writing to the console takes ages. Maybe those puts() calls could be causing it?

    – Galik
    Nov 20 '18 at 23:55













  • I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

    – VK_
    Nov 21 '18 at 11:11






  • 1





    That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

    – Rosme
    Nov 21 '18 at 15:08














1












1








1








Apparently my pollEvent is making some little pause when I continuously press a Key,



For example if a press and don't release a Key, it's calling the press event, BUT THEN is making a little pause of 0.5sec and only after that starts to call continuously the press Event
So simply put, if I just press a Key and don't release it, it gives me an output like that:



press A



pause



press A



press A



press A



press A



. . .



It's kinda problematic for my game.
my pollEvent loop:



std::map<_KEYS, bool>   Display::checkEvents()
{
resetEvents();
while (_Window.pollEvent(_Event))
{
if (_Event.type == sf::Event::Closed)
quit();
if (_Event.type == sf::Event::KeyPressed) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
puts("key up pressed");
_Events.at(_KEY_UP) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
puts("key down pressed");
_Events.at(_KEY_DOWN) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
puts("key left pressed");
_Events.at(_KEY_LEFT ) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
puts("key right pressed");
_Events.at(_KEY_RIGHT) = true;
}
}
return (_Events);
}


Any idea why ? or how I can resolve this problem ?



PS: don't mind my Event map, I think it's really far from being related with the pauses










share|improve this question














Apparently my pollEvent is making some little pause when I continuously press a Key,



For example if a press and don't release a Key, it's calling the press event, BUT THEN is making a little pause of 0.5sec and only after that starts to call continuously the press Event
So simply put, if I just press a Key and don't release it, it gives me an output like that:



press A



pause



press A



press A



press A



press A



. . .



It's kinda problematic for my game.
my pollEvent loop:



std::map<_KEYS, bool>   Display::checkEvents()
{
resetEvents();
while (_Window.pollEvent(_Event))
{
if (_Event.type == sf::Event::Closed)
quit();
if (_Event.type == sf::Event::KeyPressed) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
puts("key up pressed");
_Events.at(_KEY_UP) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
puts("key down pressed");
_Events.at(_KEY_DOWN) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
puts("key left pressed");
_Events.at(_KEY_LEFT ) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
puts("key right pressed");
_Events.at(_KEY_RIGHT) = true;
}
}
return (_Events);
}


Any idea why ? or how I can resolve this problem ?



PS: don't mind my Event map, I think it's really far from being related with the pauses







c++ sfml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 23:42









VK_VK_

164




164













  • Writing to the console takes ages. Maybe those puts() calls could be causing it?

    – Galik
    Nov 20 '18 at 23:55













  • I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

    – VK_
    Nov 21 '18 at 11:11






  • 1





    That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

    – Rosme
    Nov 21 '18 at 15:08



















  • Writing to the console takes ages. Maybe those puts() calls could be causing it?

    – Galik
    Nov 20 '18 at 23:55













  • I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

    – VK_
    Nov 21 '18 at 11:11






  • 1





    That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

    – Rosme
    Nov 21 '18 at 15:08

















Writing to the console takes ages. Maybe those puts() calls could be causing it?

– Galik
Nov 20 '18 at 23:55







Writing to the console takes ages. Maybe those puts() calls could be causing it?

– Galik
Nov 20 '18 at 23:55















I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

– VK_
Nov 21 '18 at 11:11





I don't really think, because even if it's takes ages, why does it make a pause only after the first press and then it's smooth? And anyway I put those prints in order to know what were happening, because there was already that pause before them

– VK_
Nov 21 '18 at 11:11




1




1





That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

– Rosme
Nov 21 '18 at 15:08





That is entirely normal. It's how the OS treat the input. To test, open notepad, type press 'A', and you'll observe the same behavior.

– Rosme
Nov 21 '18 at 15:08












1 Answer
1






active

oldest

votes


















0














actually I solved it while reading the sfml documentation, for the lazy people, voila :



std::map<_KEYS, bool>   Display::checkEvents()
{
resetEvents();
while (_Window.pollEvent(_Event))
{
if (_Event.type == sf::Event::Closed)
quit();
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
puts("key up pressed");
_Events.at(_KEY_UP) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
puts("key down pressed");
_Events.at(_KEY_DOWN) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
puts("key left pressed");
_Events.at(_KEY_LEFT ) = true;
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
puts("key right pressed");
_Events.at(_KEY_RIGHT) = true;
return (_Events);
}


you need to check the real time input and not the sfml pollEvent's Pool, so check your events outside the pollEvent's While



Thank you for the comments anyway :)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403266%2fsfml-pollevent-is-making-pauses-when-i-continuesly-press-keys%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    actually I solved it while reading the sfml documentation, for the lazy people, voila :



    std::map<_KEYS, bool>   Display::checkEvents()
    {
    resetEvents();
    while (_Window.pollEvent(_Event))
    {
    if (_Event.type == sf::Event::Closed)
    quit();
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
    puts("key up pressed");
    _Events.at(_KEY_UP) = true;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
    puts("key down pressed");
    _Events.at(_KEY_DOWN) = true;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
    puts("key left pressed");
    _Events.at(_KEY_LEFT ) = true;
    }
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
    puts("key right pressed");
    _Events.at(_KEY_RIGHT) = true;
    return (_Events);
    }


    you need to check the real time input and not the sfml pollEvent's Pool, so check your events outside the pollEvent's While



    Thank you for the comments anyway :)






    share|improve this answer




























      0














      actually I solved it while reading the sfml documentation, for the lazy people, voila :



      std::map<_KEYS, bool>   Display::checkEvents()
      {
      resetEvents();
      while (_Window.pollEvent(_Event))
      {
      if (_Event.type == sf::Event::Closed)
      quit();
      }
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
      puts("key up pressed");
      _Events.at(_KEY_UP) = true;
      }
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
      puts("key down pressed");
      _Events.at(_KEY_DOWN) = true;
      }
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
      puts("key left pressed");
      _Events.at(_KEY_LEFT ) = true;
      }
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
      puts("key right pressed");
      _Events.at(_KEY_RIGHT) = true;
      return (_Events);
      }


      you need to check the real time input and not the sfml pollEvent's Pool, so check your events outside the pollEvent's While



      Thank you for the comments anyway :)






      share|improve this answer


























        0












        0








        0







        actually I solved it while reading the sfml documentation, for the lazy people, voila :



        std::map<_KEYS, bool>   Display::checkEvents()
        {
        resetEvents();
        while (_Window.pollEvent(_Event))
        {
        if (_Event.type == sf::Event::Closed)
        quit();
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
        puts("key up pressed");
        _Events.at(_KEY_UP) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
        puts("key down pressed");
        _Events.at(_KEY_DOWN) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        puts("key left pressed");
        _Events.at(_KEY_LEFT ) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        puts("key right pressed");
        _Events.at(_KEY_RIGHT) = true;
        return (_Events);
        }


        you need to check the real time input and not the sfml pollEvent's Pool, so check your events outside the pollEvent's While



        Thank you for the comments anyway :)






        share|improve this answer













        actually I solved it while reading the sfml documentation, for the lazy people, voila :



        std::map<_KEYS, bool>   Display::checkEvents()
        {
        resetEvents();
        while (_Window.pollEvent(_Event))
        {
        if (_Event.type == sf::Event::Closed)
        quit();
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
        puts("key up pressed");
        _Events.at(_KEY_UP) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
        puts("key down pressed");
        _Events.at(_KEY_DOWN) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
        puts("key left pressed");
        _Events.at(_KEY_LEFT ) = true;
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
        puts("key right pressed");
        _Events.at(_KEY_RIGHT) = true;
        return (_Events);
        }


        you need to check the real time input and not the sfml pollEvent's Pool, so check your events outside the pollEvent's While



        Thank you for the comments anyway :)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 19:48









        VK_VK_

        164




        164
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53403266%2fsfml-pollevent-is-making-pauses-when-i-continuesly-press-keys%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?