TL;DR: No there really no way around having to write your "complicated" condition.
The general syntax of the logical or operator is <expression> || <expression>
.
With sf::Keyboard::Up||Down
the left-hand side is indeed an expression, but the right-hand side isn't. It's just a symbol that probably aren't even declared, and as such will not compile.
The result of the logical or operator is a bool
value, either true
or false
. The value true
can be implicitly converted to 1
and false
to 0
. In the opposite direction all non-zero values are implicitly convertible to true
while only 0
is convertible to false
.
If we take the whole expression sf::Keyboard::Up||Down||Left||Right
, and assume that the symbols would be valid without any scoping, the that expression is equal to ((sf::Keyboard::Up||Down)||Left)||Right
.
Now as to how evaluate that expression, it depends on the values of those symbols. But if we assume that only one might possibly be zero, the we have
sf::Keyboard::Up||Down
which will be true
true||Left
which will be true
true||Right
which will be true
.
So your condition
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up||Down||Left||Right))
would really be
if(sf::Keyboard::isKeyPressed(true))
which is equal to
if(sf::Keyboard::isKeyPressed(1))
which using the Key
enumeration would be equal to
if(sf::Keyboard::isKeyPressed(sf::Keyboard::B))