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

Author Topic: key press problems  (Read 1687 times)

0 Members and 1 Guest are viewing this topic.

toast9

  • Newbie
  • *
  • Posts: 8
    • View Profile
key press problems
« 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);
}

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: key press problems
« Reply #1 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)

toast9

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: key press problems
« Reply #2 on: April 22, 2015, 06:21:46 am »
Ah yes, that was it. Thank you very much!  ;D

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: key press problems
« Reply #3 on: April 22, 2015, 06:36:18 am »
no problem  :)

 

anything