SFML community forums

Help => Window => Topic started by: OrientatedCookie on April 24, 2015, 05:19:12 pm

Title: Detect if number has been pressed?
Post by: OrientatedCookie on April 24, 2015, 05:19:12 pm
How do I check if a letter is pressed down? I try to do it with if
(sf::Keyboard::isKeyPressed(sf::Keyboard::1))
but it says it expected an identifier. How can I do this?
Title: Re: Detect if number has been pressed?
Post by: Rosme on April 24, 2015, 05:21:20 pm
Use the right enum (http://www.sfml-dev.org/documentation/2.2/classsf_1_1Keyboard.php#acb4cacd7cc5802dec45724cf3314a142)? Such as sf::Keyboard::Key::NumX or sf::Keyboard::Key::NumpadX, where X is the number you want.
Title: Re: Detect if number has been pressed?
Post by: OrientatedCookie on April 24, 2015, 06:17:44 pm
is it possible to detect if two numbers have been pressed in one line of code?
Title: Re: Detect if number has been pressed?
Post by: shadowmouse on April 24, 2015, 06:21:48 pm
Code: [Select]
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num1) && sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num2))
{
    //code here
}
This should do it. Of course you can replace 1 and 2 with whatever you want, or use Numpad instead of Num like Rosme said if you want.