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

Author Topic: Keyboard key hold  (Read 5685 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Keyboard key hold
« 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

eXpl0it3r

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

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Keyboard key hold
« Reply #2 on: May 26, 2015, 05:23:39 pm »
sf::Keyboard::isKeyPressed outside the event loop

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Keyboard key hold
« Reply #3 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Keyboard key hold
« Reply #4 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*