MouseMovement.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pytomatic 作者: N0K0 项目源码 文件源码
def click(self, coords, button="left",hold=False):
        """
        Args:
            coords (touple): coords takes two arguments, either both float
                or int. If float is supplied, it will try to treat them as
                percentages. X, Y
            button (string): either "left","right" or "middle". Decides what button that
                will be sent to the running program.

        Returns:
            bool: True if successful, False otherwise.

        Raises:
            SyntaxError: The button param does not contain "left","right og "middle"
        """

        hwnd = self.win_handler.get_hwnd()

        if all(isinstance(elem, float) for elem in coords):
            coords = self.to_pixel(coords)


        logging.debug("Trying to click on:" + str(coords) + " with " + button + " button")

        x = coords[0]
        y = coords[1]

        if "right" in button.lower():
            _button_state = win32con.MK_RBUTTON
            _button_down = win32con.WM_RBUTTONDOWN
            _button_up = win32con.WM_RBUTTONUP
        elif "left" in button.lower():
            _button_state = win32con.MK_LBUTTON
            _button_down = win32con.WM_LBUTTONDOWN
            _button_up = win32con.WM_LBUTTONUP
        elif "middle" in button.lower():
            _button_state = win32con.MK_MBUTTON
            _button_down = win32con.WM_MBUTTONDOWN
            _button_up = win32con.WM_MBUTTONUP
        else:
            raise SyntaxError('"Button" needs to contain "left", "right" or "middle"')

        l_param = win32api.MAKELONG(x, y)

        win32api.SendMessage(hwnd, win32con.WM_MOUSEMOVE,0,l_param)

        time.sleep(0.2)
        win32api.SendMessage(hwnd,_button_down, _button_state, l_param)
        time.sleep(0.1)

        if not hold: #Do not release the button if hold is true
            win32api.SendMessage(hwnd, _button_up, 0, l_param)

        self._last_x = x
        self._last_y = y
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号