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

Author Topic: Oddity with Event.Key.Code(s) ?  (Read 1784 times)

0 Members and 1 Guest are viewing this topic.

arpeggiodragon

  • Newbie
  • *
  • Posts: 10
    • View Profile
Oddity with Event.Key.Code(s) ?
« on: August 11, 2010, 06:21:35 am »
This one is very straightforward. Using this code:

Code: [Select]

        while (window.GetEvent(Event))
        {
  if( Event.Key.Code == sf::Key::Down )
{  
             // setting a breakpoint here triggers when the mouse gets moved most the time.


Moving the mouse around will trigger Key::Dir events and possibly (untested) others. Very strange.

Windows XP. VC++ 09. SFML2.0


[edit] - I investigated this further and found this to be re-produceable when moving the the mouse coordinates outside of the top-left corner of the window and back.

In other words: Just shake the mouse real fast next to the window icon. :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Oddity with Event.Key.Code(s) ?
« Reply #1 on: August 11, 2010, 08:44:28 am »
What about testing the type of event before assuming it is a KeyPressed? ;)
Code: [Select]
while (window.GetEvent(Event))
{
    if (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Down)
    {
        ...
    }
}
Laurent Gomila - SFML developer

arpeggiodragon

  • Newbie
  • *
  • Posts: 10
    • View Profile
Oddity with Event.Key.Code(s) ?
« Reply #2 on: August 11, 2010, 09:45:33 am »
Oops! Yep. Works fine. Looks like it's in the documentation also (Which I should probably take a quick look at first when something goes wonky).  :)

Thanks.