SFML community forums

Help => Window => Topic started by: kurasu1415 on October 09, 2012, 10:56:42 pm

Title: Call Keyboard::isPressed() in another class?
Post by: kurasu1415 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?
Title: Re: Call Keyboard::isPressed() in another class?
Post by: eXpl0it3r 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)... ::)
Title: Re: Call Keyboard::isPressed() in another class?
Post by: kurasu1415 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.
Title: Re: Call Keyboard::isPressed() in another class?
Post by: eXpl0it3r 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. :)
Title: Re: Call Keyboard::isPressed() in another class?
Post by: Hiura 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.
Title: Re: Call Keyboard::isPressed() in another class?
Post by: kurasu1415 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.
Title: Re: Call Keyboard::isPressed() in another class?
Post by: Laurent 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?