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

Author Topic: Disabling the delay on holding down a key (HELP)  (Read 4869 times)

0 Members and 1 Guest are viewing this topic.

Dreken

  • Newbie
  • *
  • Posts: 9
    • View Profile
Disabling the delay on holding down a key (HELP)
« on: September 11, 2012, 11:54:59 pm »
I'm using SFML 2.0-rc, Windows 7, Visual Studio 2010.

Here's my snippet of code:

if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
{      
new_ypos = old_ypos - movespeed;
}

This sits inside the
while (window.pollEvent(event))
.

So, basically when I hold W, my character moves forward for a second, pauses for about 1 second, then W holds down. I know this is the delay in the operating system. The same thing happens when you hold a key on a text document.

Is there any way to get rid of this so that I don't have to wait for that 1 second delay before the character moves continuously, without changing the OS settings? I know where the OS option is, but I don't want to do this if I want to send the game to other people.

So does SFML have anything, or C++?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Disabling the delay on holding down a key (HELP)
« Reply #1 on: September 12, 2012, 12:10:24 am »
Don't put it inside the event handling loop (while(window.pollEvent(event))), it doesn't make any sense to put it there, since it's not an event, but a 'direct' device access. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Dreken

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Disabling the delay on holding down a key (HELP)
« Reply #2 on: September 12, 2012, 03:58:43 am »
Thanks, worked!