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

Author Topic: Events tiggering when they shouldn't!(SFML 1.6)  (Read 3139 times)

0 Members and 1 Guest are viewing this topic.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Events tiggering when they shouldn't!(SFML 1.6)
« on: August 04, 2012, 08:59:59 pm »
Hey guys!

I'm having a pretty interesting issue. I have a particular even that I use to close the window simply by a key press, but the thing is that it sometimes get's triggered when I don't even press any keys!
This isn't the only event that triggers itself either! I have a different event that saves a screenshot of the program running that also has gone off by itself.
Any thoughts?

The code in question.
if(Event.Key.Code == sf::Key::Escape)
{
       App.Close();
}


if (Event.Key.Code == sf::Key::F1)
{
      sf::Image Screen = App.Capture();
      Screen.SaveToFile("screenshot.jpg");
}
DSFML - SFML for the D Programming Language.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Events tiggering when they shouldn't!(SFML 1.6)
« Reply #1 on: August 04, 2012, 09:05:26 pm »
Have you taken a look at the tutorial on events? ;)

Although you didn't post all the code I'm going to assume that you don't have the following code infront of the two if statements:
if(Event.Type == sf::Event::KeyPressed)
{
   // Your ifs
}
Not checking the event type but accessing Key.Code will lead to undefined behaviour.

Additionally I advice you to use SFML 2.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Events tiggering when they shouldn't!(SFML 1.6)
« Reply #2 on: August 04, 2012, 09:13:41 pm »
Nope! And I believe that should fix it.

Although the code I was using I took from the tutorials. The code for the screenshot for example came from this one :http://www.sfml-dev.org/tutorials/1.6/graphics-window.php

The code for closing the program was just that but a little different.


Thanks for the reply though. I'll be sure to change it to make certain I check for an actual key press first!
DSFML - SFML for the D Programming Language.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Events tiggering when they shouldn't!(SFML 1.6)
« Reply #3 on: August 04, 2012, 09:20:55 pm »
Although the code I was using I took from the tutorials. The code for the screenshot for example came from this one...
I see, yeah Laurent maybe should've added the type check there too. He probably thought the readers will already be familiar with events from the other tutorial and since it isn't the main topic it would be okay to just not explain it further/add all the neded code. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything