Rewrite window._on_key_press and pep8 compatibility