SFML community forums

Help => Graphics => Topic started by: lorence30 on May 26, 2015, 03:41:53 pm

Title: Keyboard key hold
Post by: lorence30 on May 26, 2015, 03:41:53 pm
How to make so when i hold a key it wont have a delay.

say i i have a car, when i hold Left button it wont have any delay before the 2nd move of the car
Title: Re: Keyboard key hold
Post by: eXpl0it3r on May 26, 2015, 03:53:12 pm
Please describe your problem better, I've no idea what you want to achieve.

Also don't post the exact same question twice, I removed the other topic.
Title: Re: Keyboard key hold
Post by: G. on May 26, 2015, 05:23:39 pm
sf::Keyboard::isKeyPressed (http://www.sfml-dev.org/tutorials/2.3/window-inputs.php#keyboard) outside the event loop
Title: Re: Keyboard key hold
Post by: Arcade on May 26, 2015, 05:32:11 pm
If you want to continue using events, you can also check out the "The KeyPressed and KeyReleased events" section of the events tutorial: http://www.sfml-dev.org/tutorials/2.3/window-events.php. It describes what that delay is you are seeing and gives an idea of how to get around it by setting window.setKeyRepeatEnabled(false) and then use variables to hold the state of the keys. Alternatively, you can switch to using sf::Keyboard::isKeyPressed as G. mentioned.
Title: Re: Keyboard key hold
Post by: Hapax on May 27, 2015, 12:54:30 am
get around it by setting window.setKeyRepeatEnabled(false) and then use variables to hold the state of the keys.
If you're storing the states of the keys, it shouldn't be necessary to remove the repeat as each repeated keypress just sets it to the state it is in already.