SFML community forums

Help => Window => Topic started by: toast9 on April 22, 2015, 05:47:21 am

Title: key press problems
Post by: toast9 on April 22, 2015, 05:47:21 am
I'm having trouble getting keyboard events to work. Please don't say refer to the tutorials, I've looked them over hundreds of times at this point. For now all I want to happen is when I hit space it a statement cout's. What am I missing?

Code: [Select]
// in InputManager.h
sf::Event mEvent;

//in InputManager.cpp
while (Game::getInstance()->getGraphicsSystem()->pollEvent(mEvent))
{
if (mEvent.type == sf::Event::KeyPressed)
{
if (mEvent.key.code == sf::Keyboard::Space)
{
std::cout << "the space key was pressed" << std::endl;
}
}
}

//the poll event
bool GraphicsSystem::pollEvent(sf::Event theEvent)
{
return mWindow.pollEvent(theEvent);
}
Title: Re: key press problems
Post by: AlejandroCoria on April 22, 2015, 06:13:01 am
The pollEvent function needs to receive a reference (or pointer) as parameter to modify.

For example:
pollEvent(sf::Event &TheEvent)
Title: Re: key press problems
Post by: toast9 on April 22, 2015, 06:21:46 am
Ah yes, that was it. Thank you very much!  ;D
Title: Re: key press problems
Post by: AlejandroCoria on April 22, 2015, 06:36:18 am
no problem  :)