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

Author Topic: How do I get sf::Event::KeyPressed to work?  (Read 1369 times)

0 Members and 1 Guest are viewing this topic.

kingsman142

  • Newbie
  • *
  • Posts: 10
    • View Profile
How do I get sf::Event::KeyPressed to work?
« on: January 13, 2012, 04:07:23 am »
Code: [Select]
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::P)){
                cout<<"The P key was pressed temporarily."<<endl;
            }


That's what I've been trying to tweak to see if KeyPressed actually works, but I haven't had any luck yet.

The only thing I've been using at the moment is when one key has been continually pushed down instead of one key just being pushed and released.

Does it need to be in a pollevent loop?  Can anybody please tell me the correct way to use the KeyPressed event?
OS: Windows 7
SFML Version: 2
Compiler: Code::Blocks with MinGW

Haikarainen

  • Guest
How do I get sf::Event::KeyPressed to work?
« Reply #1 on: January 13, 2012, 06:26:00 am »
Yes you need to poll an event.

If you're using 2.0;

Code: [Select]
sf::RenderWindow Window;
... Initialize window and stuff ...

sf::Event Event;
while(Window.PollEvent(Event)){
... do stuff with event here, like check if Event's type is KeyPressed, and Event's Keycode is P...
}


If you're using 1.6 change Poll to Get

 

anything