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

Author Topic: Detect if number has been pressed?  (Read 2138 times)

0 Members and 1 Guest are viewing this topic.

OrientatedCookie

  • Newbie
  • *
  • Posts: 18
    • View Profile
Detect if number has been pressed?
« 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?

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Detect if number has been pressed?
« Reply #1 on: April 24, 2015, 05:21:20 pm »
Use the right enum? Such as sf::Keyboard::Key::NumX or sf::Keyboard::Key::NumpadX, where X is the number you want.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

OrientatedCookie

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Detect if number has been pressed?
« Reply #2 on: April 24, 2015, 06:17:44 pm »
is it possible to detect if two numbers have been pressed in one line of code?

shadowmouse

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Detect if number has been pressed?
« Reply #3 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.

 

anything