@@ -0,0 +1,1547 @@
+from os import popen%0Afrom sys import stdin%0Aimport re%0A%0As = re.compile('%5B :%5D')%0A%0Aclass Event:%0A    def __init__(self,key,value,old_value):%0A        self.key = key%0A        self.value = value%0A        self.old_value = old_value%0A    def is_press(self):%0A        return self.value==1 and self.old_value==0%0A    def __str__(self):%0A        return 'Event(%25s,%25d,%25d)' %25 (self.key,self.value,self.old_value)%0A%0Adef apply_deadzone(x, deadzone, scale):%0A    if x %3C 0:%0A        return (scale * min(0,x+deadzone)) / (32768-deadzone)%0A    return (scale * max(0,x-deadzone)) / (32768-deadzone)%0A%0Adef event_stream(deadzone=0,scale=32768):%0A    _data = None%0A    subprocess = popen('nohup xboxdrv','r',65536)%0A    while (True):%0A        line = subprocess.readline()%0A        if 'Error' in line:%0A            raise ValueError(line)%0A        data = filter(bool,s.split(line%5B:-1%5D))%0A        if len(data)==42:%0A            # Break input string into a data dict%0A            data = %7B data%5Bx%5D:int(data%5Bx+1%5D) for x in range(0,len(data),2) %7D%0A            if not _data:%0A                _data = data%0A                continue%0A            for key in data:%0A                if key=='X1' or key=='X2' or key=='Y1' or key=='Y2':%0A                    data%5Bkey%5D = apply_deadzone(data%5Bkey%5D,deadzone,scale)%0A                if data%5Bkey%5D==_data%5Bkey%5D: continue%0A                event = Event(key,data%5Bkey%5D,_data%5Bkey%5D)%0A                yield event%0A            _data = data%0A%0A# Appendix: Keys%0A# --------------%0A# X1%0A# Y1%0A# X2%0A# Y2%0A# du%0A# dd%0A# dl%0A# dr%0A# back%0A# guide%0A# start%0A# TL%0A# TR%0A# A%0A# B%0A# X%0A# Y%0A# LB%0A# RB%0A# LT%0A# RT%0A

Create xbox_read.py