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

Author Topic: Single key key repetition  (Read 2328 times)

0 Members and 1 Guest are viewing this topic.

robkruger

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Single key key repetition
« on: September 16, 2019, 08:11:41 pm »
I have this function to process inputs:

void sfml_game::process_input(){
  if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) m_game.get_camera().move(sf::Vector2f(-1, 0));
  if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) m_game.get_camera().move(sf::Vector2f(1, 0));
  if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) m_game.get_camera().move(sf::Vector2f(0, -1));
  if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) m_game.get_camera().move(sf::Vector2f(0, 1));
  if(sf::Keyboard::isKeyPressed(sf::Keyboard::F3)) m_debug_items = !m_debug_items;
}

Now I want to disable key repetition for F3 only, because I use it to toggle something. In it current state it just loops trough until I release the button. Is it possible to disable key repetition for one button only?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Single key key repetition
« Reply #1 on: September 16, 2019, 10:11:25 pm »
sf::Keyboard checks only the current state of the keyboard.

For state changes, you should use the normal event loop with sf::Event:
https://www.sfml-dev.org/tutorials/2.5/window-events.php
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything