python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]

python win32api sendmessage_Python win32api.SendMessage方法代码示例[通俗易懂]#需要导入模块:importwin32api[as别名]#或者:fromwin32apiimportSendMessage[as别名]defclick(self,coords,button=”left”,hold=False):”””Args:coords(touple):coordstakestwoarguments,eitherbothfloato…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

# 需要导入模块: import win32api [as 别名]

# 或者: from win32api import SendMessage [as 别名]

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/183453.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号