Advertisement
TermSpar

SFML Window and Key Events

Jun 30th, 2016
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <SFML/Graphics.hpp>
  3.  
  4. int main(){
  5.     sf::RenderWindow window(sf::VideoMode(500, 600), "SFML Tutorial", sf::Style::Titlebar | sf::Style::Close);
  6.  
  7.     //Main Loop:
  8.     while(window.isOpen()){
  9.        
  10.         sf::Event Event;
  11.  
  12.         //Event Loop:
  13.         while(window.pollEvent(Event)){
  14.            
  15.             switch(Event.type){
  16.                
  17.             case sf::Event::Closed:
  18.                 window.close();
  19.  
  20.             case sf::Event::KeyPressed:
  21.  
  22.                 if(Event.key.code == sf::Keyboard::Up){
  23.                     std::cout << "Up\n";
  24.                 }else if(Event.key.code == sf::Keyboard::Down){
  25.                     std::cout << "Down\n";
  26.                 }else if(Event.key.code == sf::Keyboard::Left){
  27.                     std::cout << "Left\n";
  28.                 }else if(Event.key.code == sf::Keyboard::Right){
  29.                     std::cout << "Right\n";
  30.                 }
  31.  
  32.             }
  33.  
  34.         }
  35.         window.display();
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement