1
Feature requests / Re: Overload of sf::Keyboard::isKeyPressed allowing input of vector of keys
« on: November 01, 2024, 12:23:44 pm »
You can use variadic templates but is quite unsafe.
I did not check the code, hope it is correct.
Now you can use just:
Problem with the code is:
1. It does not check type of arguments but at least it will generate errors if any parameter is not convertible to enum sf::Keyboard::Key
2. It has even more issues as sf::Keyboard::Key is unscoped enum which can make error messages even tougher to get to the point of error. And it can accept even incorrect parameter.
You can limit template with Concept but issue of unscoped Enum remains.
I did not check the code, hope it is correct.
auto isAnyKeyPressed(auto... keys) -> bool
{
return (sf::Keyboard::isKeyPressed(keys) || ...);
}
{
return (sf::Keyboard::isKeyPressed(keys) || ...);
}
Now you can use just:
if (isAnyKeyPressed(sf::Keyboard::A, sf::Keyboard::D, sf::Keyboard::W, sf::Keyboard::S))
// make stuff there
// make stuff there
Problem with the code is:
1. It does not check type of arguments but at least it will generate errors if any parameter is not convertible to enum sf::Keyboard::Key
2. It has even more issues as sf::Keyboard::Key is unscoped enum which can make error messages even tougher to get to the point of error. And it can accept even incorrect parameter.
You can limit template with Concept but issue of unscoped Enum remains.