Exemple #1
0
 def process_touches(self, touches):
    pressed_map_new = []
    for touch in touches:
        # TODO:  get key from keymap
        min_dist = 9999
        nearest_keypos = 9999
        for keypos in self.keymap:
            dist = abs(touch[Touch.POSITION] - keypos) 
            if dist < min_dist:
                nearest_keypos = keypos
                min_dist = dist
        pressed_map_new.append(self.keymap[nearest_keypos])
    if self.Autorepeat == True:
        for key in pressed_map_new:
                print "type", key
                xk.press_key(key)
                xk.release_key(key)
    else: 
        for key in unique(pressed_map_new + self.pressed_map_old):
            if (key in pressed_map_new) and not (key in self.pressed_map_old):
                print "press", key
                xk.press_key(key)
            if (key in self.pressed_map_old) and not (key in pressed_map_new):
                xk.release_key(key)
                print "release", key
    self.pressed_map_old = pressed_map_new[:] # shallow copy
Exemple #2
0
    def process_touches(self, touches):
       piano_map_new = []
       for touch in touches:
           new_note = XK.XK_a + int(touch[Touch.PERCENTAGE] * (XK.XK_z - XK.XK_a))
           piano_map_new.append(new_note)

       for note in range(XK.XK_a, XK.XK_z):
           if (note in piano_map_new) and not (note in self.piano_map_old):
               print "press", note
               xk.press_key(note)
           if (note in self.piano_map_old) and not (note in piano_map_new):
               xk.release_key(note)
               print "release", note
       self.piano_map_old = piano_map_new[:] # shallow copy