Example #1
0
 def doClickDragRelease(self, xMove, yMove, mouseButton=MouseButton.LEFT):
     """ Performs a click, drag, release operation from the mouse's
         current location 
         
         mouseButton - the button to click and drag with, (as specified
                       in the MouseButton class in the commands module.
                       If not specified, this method defaults to the 
                       Left mouse button.
         
         xMove       - the amount of X coordinate movement.
                   
         yMove       - the amount of Y coordinate movement.
     """
     if mouseButton == None:
         raise ValueError("mouseButton must not be None.")
     
     packets = []
     packets.append(communication.buildMouseCommand(ClickDescriptor(mouseButton, ClickType.PRESS), 0, 0))
     packets = packets + self.__motionModel.getPath(xMove, yMove)
     packets.append(communication.buildMouseCommand(ClickDescriptor(mouseButton, ClickType.RELEASE), 0, 0))
     
     for packet in packets:
         self.__serialPort.sendBytes(packet)
     
     # update location.
     self.__x += xMove
     self.__y += yMove
Example #2
0
 def doClick(self, button=MouseButton.LEFT, clickType=ClickType.CLICK):
     """ Performs a click as specified by the button and click type in the
         parameters.
         
         Params:
         button      the button to click.
         clickType   the type of click to perform.
     """
     packet = communication.buildMouseCommand(ClickDescriptor(button, clickType), 0, 0)
     self.__serialPort.sendBytes(packet)
Example #3
0
    def getPath(self, xMove, yMove):
        """ Returns a List of packets (a packet being a List of Bytes)
            that represent a series of moves to create a path from the 
            current position to the relative point specified by the xMove
            and yMove parameters.
            
            xMove       - An Integer value that represents the relative
                          x position to move the mouse to.
                          
            yMove       - An Integer value that represents the relative
                          y position to move the mouse to.
        """

        # Initialize the packet List to send back.
        packets = []
        
        # If both moves are zero, return an empty List - there is 
        # nowhere to go.
        if xMove == 0 and yMove == 0:
            return packets

        # if the x-move is zero, chunk up the vertical movements into 
        # lengths of 2.
        if xMove == 0:
            absoluteYMove = abs(yMove)
            moveCount = floor(absoluteYMove / MOVE_CHUNK)
            
            print("MC", moveCount)
            
            if (yMove < 0):
                chunk = -1 * MOVE_CHUNK
            else:
                chunk = MOVE_CHUNK
            
            print("C", chunk)
            
            
            for i in range(moveCount):
                packets.append(buildMouseCommand(ClickDescriptor(), 0, chunk))
                
            remainder_y = yMove % MOVE_CHUNK
            if chunk * remainder_y < 0:
                remainder_y = remainder_y * -1
                
            print("R", remainder_y)
            packets.append(buildMouseCommand(ClickDescriptor(), 0, remainder_y))
            print("\n end")
            
            return packets
            
        else:
            # Figure out the Slope of the line from the current position, 
            # (0,0) to the specified X and Y position.
            slope = Fraction(yMove, xMove)
            slope = slope.limit_denominator(MAX_DENOMINATOR)
            
            x_chunk = slope.denominator
            if xMove * x_chunk < 0:
                x_chunk = x_chunk * -1
              
            y_chunk = slope.numerator
            if yMove * y_chunk < 0:
                y_chunk = y_chunk * -1
            
            # Calculate the number of "whole" moves that need to be made
            moveCount = abs(floor(xMove / slope.denominator))
            
            # Build and add all of the "whole moves".
            for i in range(moveCount):
                packets.append(buildMouseCommand(ClickDescriptor(), x_chunk, y_chunk))

            # build and append the fractional, "partial" move to put us in the right
            # final position.
            remainder_x = xMove % slope.denominator
            if remainder_x * slope.denominator < 0:
                remainder_x = remainder_x * -1

            if slope.numerator == 0:
                remainder_y = 0
            else:
                remainder_y = yMove % slope.numerator
                if remainder_y * slope.numerator < 0:
                    remainder_y = remainder_y * -1
            
            packets.append(buildMouseCommand(ClickDescriptor(), remainder_x, remainder_y))
            return packets
Example #4
0
    def getPath(self, xMove, yMove):
        """ Returns a List of packets (a packet being a List of Bytes)
            that represent a series of moves to create a path from the 
            current position to the relative point specified by the xMove
            and yMove parameters.
            
            xMove       - An Integer value that represents the relative
                          x position to move the mouse to.
                          
            yMove       - An Integer value that represents the relative
                          y position to move the mouse to.
        """

        # Initialize the packet List to send back.
        packets = []

        # If both moves are zero, return an empty List - there is
        # nowhere to go.
        if xMove == 0 and yMove == 0:
            return packets

        # if the x-move is zero, chunk up the vertical movements into
        # lengths of 2.
        if xMove == 0:
            absoluteYMove = abs(yMove)
            moveCount = floor(absoluteYMove / MOVE_CHUNK)

            print("MC", moveCount)

            if (yMove < 0):
                chunk = -1 * MOVE_CHUNK
            else:
                chunk = MOVE_CHUNK

            print("C", chunk)

            for i in range(moveCount):
                packets.append(buildMouseCommand(ClickDescriptor(), 0, chunk))

            remainder_y = yMove % MOVE_CHUNK
            if chunk * remainder_y < 0:
                remainder_y = remainder_y * -1

            print("R", remainder_y)
            packets.append(buildMouseCommand(ClickDescriptor(), 0,
                                             remainder_y))
            print("\n end")

            return packets

        else:
            # Figure out the Slope of the line from the current position,
            # (0,0) to the specified X and Y position.
            slope = Fraction(yMove, xMove)
            slope = slope.limit_denominator(MAX_DENOMINATOR)

            x_chunk = slope.denominator
            if xMove * x_chunk < 0:
                x_chunk = x_chunk * -1

            y_chunk = slope.numerator
            if yMove * y_chunk < 0:
                y_chunk = y_chunk * -1

            # Calculate the number of "whole" moves that need to be made
            moveCount = abs(floor(xMove / slope.denominator))

            # Build and add all of the "whole moves".
            for i in range(moveCount):
                packets.append(
                    buildMouseCommand(ClickDescriptor(), x_chunk, y_chunk))

            # build and append the fractional, "partial" move to put us in the right
            # final position.
            remainder_x = xMove % slope.denominator
            if remainder_x * slope.denominator < 0:
                remainder_x = remainder_x * -1

            if slope.numerator == 0:
                remainder_y = 0
            else:
                remainder_y = yMove % slope.numerator
                if remainder_y * slope.numerator < 0:
                    remainder_y = remainder_y * -1

            packets.append(
                buildMouseCommand(ClickDescriptor(), remainder_x, remainder_y))
            return packets