title: Detect the state of a switch connected to USB with python
body: <p>I would like to ask if there is a way to detect the state of a switch, connected through a usb. The switch has 2 states, on and off. Possibly with Python, on Windows.</p>
  
  <p>Or, am I able to implement a script that will consider the switch to be a keyboard extension.</p>
  
  <p>Thank you in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>#import usb.core
  #import usb.util
  import usb
  
  # find our device
  #dev = usb.core.find(find_all=True)
  busses = usb.busses()
  # was it found?
  #if dev is None:
  #    raise ValueError('Device not found')
  
  
  for bus in busses:
      devices = bus.devices
      for dev in devices:
          try:
              _name = usb.util.get_string(dev.dev, 19, 1)
          except:
              continue
          #dev.set_configuration()
          #cfg = dev.get_active_configuration()
          #interface_number = cfg[(0,0)].bInterfaceNumber
          #5alternate_settting = usb.control.get_interface(interface_number)
          print "Device name:",_name
          print "Device:", dev.filename
          print "  idVendor:",hex(dev.idVendor)
          print "  idProduct:",hex(dev.idProduct)
          for config in dev.configurations:
              print "  Configuration:", config.value
              print "    Total length:", config.totalLength 
              print "    selfPowered:", config.selfPowered
              print "    remoteWakeup:", config.remoteWakeup
              print "    maxPower:", config.maxPower
          print
  </code></pre>