(self, pos)
Record mouse movement.
Record mouse movement.
Record mouse movement .
def mouse_mouse(self, pos):
        """Record mouse movement."""
        try:
            prev_mouse_pos = self.mouse_pos
        except AttributeError:
            prev_mouse_pos = None

        self.mouse_pos = pos

        # In certain cases such as the login screen, the position can't be read
        if self.mouse_pos is None:
            if prev_mouse_pos is not None:
                print('Unknown mouse position')
            return

        # Calculate the distance (or speed)
        distance = calculate_distance(self.mouse_pos, prev_mouse_pos)
        if distance:
            self.send_event(ProcessEvent.MouseDistance, distance)

        # Draw a line from the previous position
        pixels = [self.mouse_pos]
        if prev_mouse_pos is not None:
            pixels.extend(calculate_line(self.mouse_pos, prev_mouse_pos))
            pixels.append(prev_mouse_pos)

        # Determine which monitor each pixel is on
        start_monitor = match_pixel_to_monitor(pixels[0], self.monitor_data)
        if len(pixels) == 1:
            end_monitor = start_monitor
        else:
            end_monitor = match_pixel_to_monitor(pixels[-1], self.monitor_data)

        if start_monitor == end_monitor:
            monitor_mapping = {pixel: start_monitor for pixel in pixels}
        else:
            monitor_mapping = {
                pixels[0]: start_monitor,
                pixels[-1]: end_monitor,
            }
            for pixel in pixels[1:-1]:
                monitor_mapping[pixel] = match_pixel_to_monitor(pixel, self.monitor_data)

        for pixel, i in monitor_mapping.items():
            x1, y1, x2, y2 = self.monitor_data[i]
            width = x2 - x1
            height = y2 - y1
def mouse_mouse ( self , pos ) : try : prev_mouse_pos = self . mouse_pos except AttributeError : prev_mouse_pos = None self . mouse_pos = pos # In certain cases such as the login screen, the position can't be read if self . mouse_pos is None : if prev_mouse_pos is not None : print ( 'Unknown mouse position' ) return # Calculate the distance (or speed) distance = calculate_distance ( self . mouse_pos , prev_mouse_pos ) if distance : self . send_event ( ProcessEvent . MouseDistance , distance ) # Draw a line from the previous position pixels = [ self . mouse_pos ] if prev_mouse_pos is not None : pixels . extend ( calculate_line ( self . mouse_pos , prev_mouse_pos ) ) pixels . append ( prev_mouse_pos ) # Determine which monitor each pixel is on start_monitor = match_pixel_to_monitor ( pixels [ 0 ] , self . monitor_data ) if len ( pixels ) == 1 : end_monitor = start_monitor else : end_monitor = match_pixel_to_monitor ( pixels [ - 1 ] , self . monitor_data ) if start_monitor == end_monitor : monitor_mapping = { pixel : start_monitor for pixel in pixels } else : monitor_mapping = { pixels [ 0 ] : start_monitor , pixels [ - 1 ] : end_monitor , } for pixel in pixels [ 1 : - 1 ] : monitor_mapping [ pixel ] = match_pixel_to_monitor ( pixel , self . monitor_data ) for pixel , i in monitor_mapping . items ( ) : x1 , y1 , x2 , y2 = self . monitor_data [ i ] width = x2 - x1 height = y2 - y1