Just knew this will be
that from this description..
By the way, this code is too long. You're supposed to post
minimal examples.
while(Window.pollEvent(Event))
{
if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
Window.close();
}
Event.key.code reads from a union without checking if it's really a key event.
position.x and key.code are stored in the same memory space in that union so you're interpreting x position of mouse as a key code number(so finally you reach the key code for esc when mouse x increases and program closes).