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

Author Topic: Call Keyboard::isPressed() in another class?  (Read 3697 times)

0 Members and 1 Guest are viewing this topic.

kurasu1415

  • Newbie
  • *
  • Posts: 37
    • View Profile
    • Email
Call Keyboard::isPressed() in another class?
« on: October 09, 2012, 10:56:42 pm »
Hey guys,
So I want to be able to call Keyboard::isPressed() in another class. Basically, I have a class that handles mapping keyboard and gamepad input. Do I need to have a pointer to my original sf::Window to call Keyboard::isPressed() ? If not, what do I need to pass to my class/function in order to check what keys are pressed?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #1 on: October 09, 2012, 10:59:43 pm »
Nothing. ;D

Just include the needed header and start using sf::Keyboard. sf::Keyboard doesn't depend on events or anything it works on its own.
Btw you could've just tested this out (or read the documentation)... ::)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kurasu1415

  • Newbie
  • *
  • Posts: 37
    • View Profile
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #2 on: October 09, 2012, 11:56:29 pm »
I looked over the docs, and I didn't see where it said I could call it from anywhere I wanted. I didn't test because I assumed it would be more difficult than that. Thanks for the help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #3 on: October 10, 2012, 01:02:56 am »
I looked over the docs, and I didn't see where it said I could call it from anywhere I wanted. I didn't test because I assumed it would be more difficult than that. Thanks for the help.
But it also didn't say anything about that you have to call it only in situation x, thus you usually can conclude the contrary. ;)
It doesn't matter how or what you assume, you can always try to test things. If your assumptions are right or wrong will be shown by the test. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #4 on: October 10, 2012, 01:12:15 am »
Maybe were you confused by the static keyword ? If that's the case I can't emphasis enough how important it is to read a good book on C++ before starting doing some fancy stuff.
SFML / OS X developer

kurasu1415

  • Newbie
  • *
  • Posts: 37
    • View Profile
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #5 on: October 10, 2012, 01:44:19 am »
I think what hurt me here is the assumption that Keyboard was handled similarly to an event. I looked into this last night, and I guess I either didn't look in the right place, or I missed the static keyword (dunno how). I know what static means, lol.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Call Keyboard::isPressed() in another class?
« Reply #6 on: October 10, 2012, 08:09:17 am »
Quote
I think what hurt me here is the assumption that Keyboard was handled similarly to an event
Isn't the tutorial clear enough about the difference between these two APIs?
Laurent Gomila - SFML developer