An sf::Event is a union (http://en.cppreference.com/w/cpp/language/union) and due to this, the key code should never be queried unless the event is confirmed to be a key event type.
For example:
if (event.type == sf::Event::Keypressed)
{
if (event.key.code == sf::Keyboard::Escape)
escapeWasPressed();
}