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

Author Topic: Accessing sf::Keyboard  (Read 920 times)

0 Members and 1 Guest are viewing this topic.

sircuddles

  • Newbie
  • *
  • Posts: 10
    • View Profile
Accessing sf::Keyboard
« on: February 03, 2013, 12:53:36 am »
Apologies for the basic/noob question, but I want to understand what's going on since I really have no idea.

I have a player class that accesses sf::Keyboard, and I'm not really sure how it's able to access it and how it gets populated with any sort of data.

void Paddle::update(const float& t, const sf::RenderWindow& window) {
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
                xVel = -xSpeed * t;
        }

This is an example from Paddle.cpp.  The function is called after window.pollEvent() takes place in Main.  I'm just curious how my class, seemingly unconnected to anything, gets access to it and how it is populated with values (because it works wonderfully).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10822
    • View Profile
    • development blog
    • Email
AW: Accessing sf::Keyboard
« Reply #1 on: February 03, 2013, 07:07:28 am »
The class is not connected to the event system, but pulls the real time data directly from the device. By using static functions you can call them from any scope (i.e. similar to for example std::cout).
If you want to know more details, I suggest you should go and take a look at the source code. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/