title: How to use keyboard event as part of a conditional statement
body: <p>I'm trying to make a program that outputs a key press event as a response to another keyboard event.  How do I get it to use the particular value of the key pressed in a conditional statement?  The codes I try seem to be skipping the conditional statement altogether.</p>
  
  <p>Initially tried <code>[if key == '1':],</code> then tired by <code>[if key == 1:]</code>.  Also tried various means of assigning [key] to a variable.  Also tried [print('2')] instead of using <code>[pyautogui.typewrite('2')]</code>.  Tried putting the code both in on_press(key) and in on_release(key).</p>
  
  <p>`</p>
  
  <pre><code>    import pyautogui
      from pynput.keyboard import Key, Listener
  
      def on_press(key):
          print('{0} pressed'.format(key))
  
      def on_release(key):
          print('{0} release'.format(key))
          k = format(key)
          if k == '1':       #THIS IS THE PART I CAN'T GET TO WORK
              pyautogui.typewrite('2', 0.5)
          if key == Key.esc:
      # Stop listener
              return False
      # Collect events until released
      with Listener(
          on_press=on_press,
          on_release=on_release) as listener:
      listener.join()
  </code></pre>
  
  <p>`</p>
  
  <p>Expected to output '2' whenever I press '1' on the keyboard(in addition to the output of the keypress and keyrelease event).  The output for the pressing of '1' doesn't work.</p>