document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #~ WiimotePyConnect v1.5
  2.  
  3. import cwiid
  4.  
  5. c = input(\'Cuantos controles va a conectar? \')
  6. wm = []
  7. for i in range(c):
  8.     print \'Presione 1+2 en el Wiimote \' + str(i+1) + \'...\'
  9.     wm.append(cwiid.Wiimote())
  10.     wm[i].rpt_mode = cwiid.RPT_BTN | cwiid.RPT_IR | cwiid.RPT_ACC | cwiid.RPT_EXT
  11.     wm[i].led = i+1
  12.  
  13. bWiimote = {8:\'A\', 4:\'B\', 2:\'1\', 1:\'2\', 16:\'-\', 4096:\'+\', 128:\'Home\', 2048:\'Up\', 1024:\'Down\', 256:\'Left\', 512:\'Right\'}
  14. bClassic = {16:\'a\', 64:\'b\', 8:\'x\', 32:\'y\', 4096:\'-\', 1024:\'+\', 8192:\'L\', 512:\'R\', 128:\'zL\', 4:\'zR\', 2048:\'Home\', 1:\'Up\', 16384:\'Down\', 2:\'Left\', 32768:\'Right\'}
  15. bNunchuk = {2:\'c\', 1:\'Z\'}
  16.  
  17. def checkPressed(w, mapp):
  18.     buttons = w[\'buttons\']
  19.     bn = sorted(mapp.keys())
  20.     bn.reverse()
  21.     p = []
  22.     for i in bn:
  23.         if i <= buttons:
  24.             p.append(mapp[i])
  25.             buttons -= i
  26.     return p
  27.  
  28. def checkConnected(wm, c):
  29.     keys = wm.state.keys()
  30.     return c in keys
  31.  
  32. while True:
  33.     #~ #Buttons pressed
  34.     classic = []
  35.     wiimote = []
  36.     nunchuk = []
  37.     pressed = []
  38.     for i in range(c):
  39.         if checkConnected(wm[i],\'nunchuk\'):
  40.             nunchuk = checkPressed(wm[i].state[\'nunchuk\'],bNunchuk)
  41.         elif checkConnected(wm[i], \'classic\'):
  42.             classic = checkPressed(wm[i].state[\'classic\'],bClassic)
  43.         wiimote = checkPressed(wm[i].state,bWiimote)
  44.         pressed.append({\'classic\':classic, \'wiimote\':wiimote, \'nunchuk\':nunchuk})
  45.     print pressed
');