So my question is: How do I detect a single Key press in SFML?
You already implemented this case:
while(mainWindow->pollEvent(event))
{
switch (event.type)
{
case sf::Event::KeyPressed: // Here you detect if you press a key
...
}
}
To get the actual key you say: event.key.code, so for example
if(event.key.code == sf::Keyboard::Escape)
mainWindow.close();
Yes, don't hesitate to experiment with different approaches. The command system from the book is just one possible way of doing it, it also has its drawbacks.
But in any case, I would think about a design that separates input handing and game logic. At least if you plan to make things scalable (e.g. allow key rebinding), you should avoid code like
if (/* Space key pressed */)
player.jump();