title: How to make a button press have different outputs depending on time pressed in Python?
body: <p>I am attempting to learn how to program a little. I am making this script for my Raspberry Pi, but the concept doesn't have to be specifically for it. I want to have a button press that will execute one of two commands:</p>
  
  <p>If held for one second, then run command A
  If held for five seconds, then run command B
  It is okay for command A to run multiple times while waiting for B to register.</p>
  
  <p>Here is my script, and afterwards I will explain its purpose:</p>
  
  <pre><code>import RPi.GPIO as GPIO
  import uinput
  inport time
  import os
  
  GPIO.setmode(GPIO.BCM)
  GPIO.setup(17, GPIO.IN)
  
  def main():
       events = (
            uinput.KEY_ESC,
            )
  
       device = uinput.Device(events)
  
       device.emit(uinput.KEY_ESC, 1) #Press
       device.emit(uinput.KEY_ESC, 0) #Release
  </code></pre>
  
  <p>Then, here are the two things that I want to have added:</p>
  
  <pre><code>while 1:
  
       if time.sleep(1)
       if GPIO.input(17)==True:
            main()
            break
  
  while 1:
  
       if time.sleep(10)
       if GPIO.input(17)==True:
            os.system("sudo reboot")
            break
  </code></pre>
  
  <p>Essentially, this script will cause the button to have two purposes. Pressing it for one second will emulate a keystroke of the key ESC. Pressing it for ten seconds will cause it to reboot the system. How can I have the two happen at the same time? Learning Python is pretty challenging for me, but I've had no programming experience at all until now.</p>