from operationscore.Behavior import * class MITDoors(Behavior): """MITDoors is a case-specific behavior to map keypresses to specific locations. Written for Kuan 1/26/11 by RCOH""" def behaviorInit(self): self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105], 'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]} def processResponse(self, sensorInputs, recursiveInputs): ret = [] for data in sensorInputs: key = chr(data['Key']) if key in self.keymapping: bounds = self.keymapping[key] data = dict(data) data['Left'], data['Right'] = bounds data['Bottom'] = self['Bottom'] data['Location'] = (sum(bounds) / 2., self['Bottom']) ret.append(data) return (ret, [])