SFML community forums

Help => General => Topic started by: game_maker on January 27, 2013, 11:43:53 pm

Title: Function do not works
Post by: game_maker on January 27, 2013, 11:43:53 pm
Hi!

I am using this code:

sf::RenderWindow window(sf::VideoMode(800, 600, 32), "");
window.setKeyRepeatEnabled(false);

But, when I check if a key was pressed, the event runs (is triggered) 2 times.

To check the key, I use:

void GameManager::Update(sf::Event event)
{
ReleasedKey=sf::Keyboard::KeyCount; //basically "NoKey"
PressedKey =sf::Keyboard::KeyCount; //bascically "No Key"

switch (event.type)
{
    case sf::Event::KeyReleased: ReleasedKey=event.key.code;
    case sf::Event::KeyPressed: PressedKey=event.key.code;
default: break;
}

}

And:

GameManager game;
...
while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
            game.Update(event);

            if (game.keyboard_check_pressed(sf::Keyboard::A))
                std::cout << 'A' << endl;
        }

I can not find the error... Please help me.

Note: I use Windows 7, Code::Blocks, MinGW, SFML 2.0.
Title: Re: Function do not works
Post by: eXpl0it3r on January 27, 2013, 11:49:25 pm
Please read this (http://en.sfml-dev.org/forums/index.php?topic=5559.0) then... ;)

What exact SFML version, what OS, what hardware, etc...

My blind guess would be Linux and this thread (http://en.sfml-dev.org/forums/index.php?topic=10156.msg69754#msg69754) (yes the search function works even on your end). :)
Title: Re: Function do not works
Post by: G. on January 27, 2013, 11:59:18 pm
My blind guess (since you're using win7 and not linux :D): unless you know what you're doing, use break in your switch cases.

Here for one key pressed (and released) you go in your second case twice, once when the key is pressed, another one when the key is released.
Title: Re: Function do not works
Post by: game_maker on January 27, 2013, 11:59:51 pm
Quote
Please read this then...
OK...

Quote
What exact SFML version, what OS, what hardware, etc...
OK...

Quote
My blind guess would be Linux
Wrong.

Quote
and this thread (yes the search function works even on your end).
I saw this topic and I imagined that someone would tell him.
And I do not like (I hate) this internal search engine.
I always 'google' this way: site:sfml-dev.org 'my keywords here'.
I 'googled' before asking.
------------------------------------------------------------
Edited:

Quote
use break in your switch cases
Solved.

Thanks!
---------------------------
eXpl0it3r, I admire you so much. Sorry for anything.

Thanks.
Title: Re: Function do not works
Post by: eXpl0it3r on January 28, 2013, 02:21:28 am
And I do not like (I hate) this internal search engine.
Yeah, I wish it was better and specially that the MySQL wouldn't disconnect randomly when doing a full search... :-\

eXpl0it3r, I admire you so much. Sorry for anything.
;D