Exemplo n.º 1
0
    def __call__(self, x=None, y=None, displayNumber=None, center=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(
                len(mons)):  # on what monitor (= mon) is the pointer ?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        SetCursorPos(x, y)
Exemplo n.º 2
0
 def __call__(self, x, y):
     point = POINT()
     GetCursorPos(point)
     if x is None:
         x = 0
     if y is None:
         y = 0
     SetCursorPos(point.x + x, point.y + y)
Exemplo n.º 3
0
 def __call__(self, x, y, useAlternateMethod=False):
     if x is None:
         x = 0
     if y is None:
         y = 0
     if useAlternateMethod:
         mouse_event2(MOUSEEVENTF_MOVE, x, y)
     else:
         point = POINT()
         GetCursorPos(point)
         SetCursorPos(point.x + x, point.y + y)
Exemplo n.º 4
0
    def __call__(self,
                 x=None,
                 y=None,
                 displayNumber=None,
                 center=False,
                 useAlternateMethod=False):
        point = POINT()
        GetCursorPos(point)
        X = point.x
        Y = point.y
        mons = EnumDisplayMonitors(None, None)
        mons = [item[2] for item in mons]
        for mon in range(len(mons)):  # on what monitor (= mon) is the cursor?
            m = mons[mon]
            if m[0] <= X and X <= m[2] and m[1] <= Y and Y <= m[3]:
                break
        if displayNumber is None:
            displayNumber = mon

        monitorDimensions = GetMonitorDimensions()
        try:
            displayRect = monitorDimensions[displayNumber]
        except IndexError:
            displayNumber = 0
            displayRect = monitorDimensions[displayNumber]
        if center:
            x = displayRect[2] / 2
            y = displayRect[3] / 2

        if x is None:
            x = X - mons[displayNumber][0]
        if y is None:
            y = Y - mons[displayNumber][1]

        x += displayRect[0]
        y += displayRect[1]
        if useAlternateMethod:
            x = x * 65535 / GetSystemMetrics(0)
            y = y * 65535 / GetSystemMetrics(1)
            mouse_event2(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y)
        else:
            SetCursorPos(x, y)
Exemplo n.º 5
0
    def run(self):
        stop = False
        point = POINT()
        while True:
            self.lastTime = clock()
            if not self.receiveQueue.empty():
                data = self.receiveQueue.get()
                if data[0] == -1:
                    break
                elif data[0] == -2:
                    stop = True
                else:
                    self.newAngle = radians(data[0])
                    self.initSpeed = data[1]
                    self.maxSpeed = data[2]
                    self.acceleration = data[3]
                    self.useAlternateMethod = data[4]

            if stop:
                self.acceleration = 0
                self.speed = 0
                stop = False
                continue

            if self.acceleration == 0:
                sleep(0.05)
                continue

            ticks = 10
            if self.speed == 0:
                self.currentAngle = self.newAngle
                self.speed = self.initSpeed
            else:
                diff = self.newAngle - self.currentAngle
                if diff > pi:
                    diff = diff - 2 * pi
                elif diff < -1 * pi:
                    diff = diff + 2 * pi
                self.currentAngle = self.currentAngle + (diff / 20)

            self.speed = self.speed + (self.speed * self.acceleration * ticks)
            if self.speed > self.maxSpeed:
                self.speed = self.maxSpeed
            elif self.speed <= 0:
                self.speed = 0

            factor = self.speed * (ticks / 10)
            xCurrent = sin(self.currentAngle) * factor + self.xRemainder
            yCurrent = -1 * cos(self.currentAngle) * factor + self.yRemainder

            x = int(xCurrent)
            y = int(yCurrent)

            self.xRemainder = xCurrent - x
            self.yRemainder = yCurrent - y
            try:
                if self.useAlternateMethod:
                    mouse_event2(MOUSEEVENTF_MOVE, x, y)
                else:
                    GetCursorPos(point)
                    SetCursorPos(point.x + x, point.y + y)
            except:
                pass
            if self.speed == 0:
                self.acceleration = 0
            waitTicks = 0.01 - (clock() - self.lastTime)
            if waitTicks < 0:
                waitTicks = 0.0
            sleep(waitTicks)
Exemplo n.º 6
0
    def run(self):
        upTime = 0
        point = POINT()
        while True:
            self.lastTime = clock()
            if not self.receiveQueue.empty():
                data = self.receiveQueue.get()
                if data == -1:
                    break
                elif data == -2:
                    upTime = clock()
                else:
                    self.newAngle = radians(data)
                    self.acceleration = self.accelerationFactor
                    upTime = 0

            if upTime != 0 and clock() - upTime > 0.05:
                self.acceleration = 0
                self.speed = 0

            if self.acceleration == 0:
                sleep(0.05)
                continue

            ticks = 10
            if self.speed == 0:
                self.currentAngle = self.newAngle
                self.speed = self.iniSpeed
                #self.speed = 0.06
            else:
                diff = self.newAngle - self.currentAngle
                if diff > pi:
                    diff = diff - 2 * pi
                elif diff < -1 * pi:
                    diff = diff + 2 * pi
                self.currentAngle = self.currentAngle + (diff / 20)

            self.speed = self.speed + (self.speed * self.acceleration * ticks)
            if self.speed > self.maxSpeed:
                self.speed = self.maxSpeed
            elif self.speed <= 0:
                self.speed = 0

            factor = self.speed * (ticks / 10)
            xCurrent = sin(self.currentAngle) * factor + self.xRemainder
            yCurrent = -1 * cos(self.currentAngle) * factor + self.yRemainder

            x = int(xCurrent)
            y = int(yCurrent)

            self.xRemainder = xCurrent - x
            self.yRemainder = yCurrent - y
            try:
                GetCursorPos(point)
                SetCursorPos(point.x + x, point.y + y)
            except:
                pass
            if self.speed == 0:
                self.acceleration = 0
            waitTicks = 0.01 - (clock() - self.lastTime)
            if waitTicks < 0:
                waitTicks = 0.0
            sleep(waitTicks)