How to know the direction of the mouse?

1

I would like to make a small program that indicates to which position the mouse is moving (right, left, high, low, right and high, right and low ...), but I can not come to a logic that give this result.

Examples: If the Y and X are being incremented, then the mouse will be going up and right at the same time. If only X is being incremented, then the mouse will be going right. If the X is being decremented, the mouse is going to the left. And so on.

I'vethoughtofways,butnothingworks.Ifsomebodycanhelpme,Iappreciateitalot.

importpynputdefPosition():mouse=pynput.mouse.Controller()whileTrue:position_anterior=mouse.position[0]#mouse.positionretornaumatuplacom(x,y)position_atual=mouse.position[0]ifposition_atual>position_anterior:#print("direita")
        elif position_atual < position_anterior:
            print("esquerda")
        elif position_atual == position_anterior:
            print("parado")
Position()
    
asked by anonymous 27.10.2018 / 10:34

1 answer

2

It has to compare with the previous position, not twice with it.

Something like this:

    import pynput

    def Position():
        mouse = pynput.mouse.Controller()
        position_anterior = mouse.position[0]

        while True:
            position_atual = mouse.position[0]
            if position_atual > position_anterior:
                print("direita")
            elif position_atual < position_anterior:
                print("esquerda")
            elif position_atual == position_anterior:
                print("parado")
            position_anterior = position_atual

    Position()
    
27.10.2018 / 11:18