SFML pollEvent is making pauses when I continuesly press Keys
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
add a comment |
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
Writing to the console takes ages. Maybe thoseputs()
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
add a comment |
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
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
c++ sfml
asked Nov 20 '18 at 23:42
VK_VK_
164
164
Writing to the console takes ages. Maybe thoseputs()
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
add a comment |
Writing to the console takes ages. Maybe thoseputs()
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
add a comment |
1 Answer
1
active
oldest
votes
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 :)
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 :)
add a comment |
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 :)
add a comment |
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 :)
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 :)
answered Nov 22 '18 at 19:48
VK_VK_
164
164
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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