1 from operationscore.Behavior import *
2 import math
3 import util.ComponentRegistry as compReg
5 """MITDoors is a case-specific behavior to map keypresses to specific locations. Written for
6 Kuan 1/26/11 by RCOH"""
7
9 self.keymapping = {'q':[2,19], 'w':[22,36], 'e':[37,49], 'r':[52,69], 't':[76,91], 'y':[94,105],
10 'u':[106,117], 'i':[123,154], 'o':[158,161], 'p':[164,167], '[':[172,184]}
11 screenWidth = compReg.getComponent('Screen').getSize()[2]
12 maxKey = max([max(self.keymapping[v]) for v in self.keymapping])
13 mult = screenWidth / float(maxKey)
14 for k in self.keymapping:
15 self.keymapping[k] = [int(val*mult) for val in self.keymapping[k]]
17 ret = []
18 for data in sensorInputs:
19 key = chr(data['Key'])
20 if key in self.keymapping:
21 bounds = self.keymapping[key]
22 data = dict(data)
23 data['Left'], data['Right'] = bounds
24 data['Bottom'] = self['Bottom']
25 data['Location'] = (sum(bounds) / 2., self['Bottom'])
26 data['Oscillate'] = False
27 ret.append(data)
28 return (ret, [])
29