title: Using 'esc' to close PySimpleGUI window
body: <p>I have a PySimpleGUI window that I want to maximise, eventually without a title bar. I want to use the 'esc' key to close the window.</p>
  <p>Here's my (simplified) code:</p>
  <pre><code>import msvcrt
  import PySimpleGUI as sg
  
  layout = [[sg.Text(size=(40, 1), font=(&quot;Arial&quot;, (32)), justification='left', key='-TEXT-')]]
  window = sg.Window(title=&quot;Window&quot;, layout=layout, grab_anywhere=True, finalize = True, no_titlebar=False)
  
  window.maximize()
  
  escape = False
  
  while True:
  
      event, values = window.read()
  
      if msvcrt.kbhit() and msvcrt.getch() == chr(27).encode():
          escape = True
      else:
          ecape = False
  
      if event == sg.WIN_CLOSED or event == 'Cancel' or escape == True:
          break
  
  window.close()
  </code></pre>
  <p>The close button works fine - but pressing escape does nothing.</p>
  <p>I've tried several of the answers <a href="https://stackoverflow.com/questions/5137238/how-to-detect-escape-keypress-in-python">here</a>, but with no luck.</p>
  <p>What's going wrong, and how can I fix it?</p>