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

Author Topic: Is KeyPressed suppossed to fire once or continuously?  (Read 2612 times)

0 Members and 2 Guests are viewing this topic.

Kian

  • Newbie
  • *
  • Posts: 44
    • View Profile
Is KeyPressed suppossed to fire once or continuously?
« on: July 09, 2011, 05:52:15 am »
Been working on my event loop, and noticed something that I wasn't expecting.

When you hold a key down, is it suppossed to spam 'KeyPressed' events, followed by a single 'KeyReleased' event when you let go, or am I reading the events wrong somehow?

Ok, did a little test. Apparently it has to do with the keyboard repeat rate in the Windows Control Panel. KeyPressed Events are fired at the same rate that you select there. Any clue how to avoid this (other than disregarding key pressed events until you find an appropriate keyreleased event, which don't get spammed)?

Further research would seem to indicate that this is how Windows is suppossed to behave. Since I was using a toggle anyway, it doesn't actually matter if I receive a lot of KeyPressed events as long as they don't alternate. So consider the question solved.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is KeyPressed suppossed to fire once or continuously?
« Reply #1 on: July 09, 2011, 09:28:32 am »
Window::EnableKeyRepeat(bool) is what you're looking for.
Laurent Gomila - SFML developer

Kian

  • Newbie
  • *
  • Posts: 44
    • View Profile
Is KeyPressed suppossed to fire once or continuously?
« Reply #2 on: July 10, 2011, 12:44:38 am »
Oh yeah! That's exactly it. Thanks :D