title: How to detect when button is pressed second time in function
body: <p>I am writting a code on Raspberry Pi in Python3 to control a door opening. I have a code that is triggered by button being pressed and it works fine. Later in the code I want to take some additional actions when the same button is pressed again and this is not working.</p>
  
  <p>Can someone help me with this?</p>
  
  <p>Thanks.</p>
  
  <pre><code>#/usr/bin/python3
  
  def read_code():
      kod = ''
      klawisz = ''     
      for event in dev.read_loop():
          if event.type == ecodes.EV_KEY:
              e = categorize(event)
              if e.keystate == e.key_down:
                  klawisz = e.keycode[4:]
                  if klawisz != "ESC":
                      kod = (kod + klawisz)
                      print(kod)
                  else:
                      break
      return kod
  
  while True:
      button_state = GPIO.input(Button)
      if button_state == 0:
          print('TYPE CODE')
          while read_code() !='1234':
              GPIO.output(LED,GPIO.HIGH)
              print('WRONG CODE')
          else:
              print('CODE IS CORRECT')
         /// trying to detect button being pressed again but not working///
              button_state2 = GPIO.input(Button)
              if button_state2 == 0:
              print('TYPE CODE')
              while read_code() !='5678':
                  GPIO.output(LED,GPIO.HIGH)
                  print('WRONG CODE')
              else:
                  print('CODE IS CORRECT')
  
      else:
          GPIO.output(LED,GPIO.LOW)
  </code></pre>