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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 2005中文博客排名报告「建议收藏」

    2005中文博客排名报告「建议收藏」2005中文博客排名报告发布机构:时代财富科技公司 摘要:2004年11月时代财富科技公司推出了中文Blog排行榜,得到了大众及媒介的广泛关注,也成为众多同行和资本市场了解中文博客网站的重要参考。历经2005年上半年中文Blog托管网站的飞速发展时期,博客网站也正经历着重新的洗牌和残酷的市场竞争。经过长时间的调查和分析,结合大量的用户体验,时代财富科技公司于2005年8月隆重推出《

    2022年7月12日
    17
  • RailsCasts批量下载地址之Ruby代码

    RailsCasts批量下载地址之Ruby代码

    2022年3月12日
    56
  • mysql有关运维的面试题_mysql数据库运维面试题「建议收藏」

    mysql有关运维的面试题_mysql数据库运维面试题「建议收藏」1.登陆数据库(1)单实例mysql-uroot-poldboy(2)多实例mysql-uroot-poldboy-S/data/3306/mysql.sock2.查看数据库版本及当前登录用户是什么mysql>selectversion();查看版本+————+|version()|+————+|5.5.22-log|+——-…

    2022年6月8日
    91
  • centos7安装yum[通俗易懂]

    centos7安装yum[通俗易懂]centos7系统yum卸载后重新安装1.rpm包准备yum卸载后软件安装很麻烦,重新安装yum,先把相关rpm包下载下来,传到服务器。下载地址:http://mirrors.163.com/centos/7/os/x86_64/Packages/(我的是centos764位,所以是这个路径,看网址就可以知道每个路径是干嘛的,下载自己版本所需的即可,各个包小版本有变化,注意进行选择)…

    2022年6月4日
    45
  • pycharm删除所有注释_pycharm怎么取消注释

    pycharm删除所有注释_pycharm怎么取消注释1Pycharm去掉项目所有#注释通过快捷键ctrl+shift+R进入项目全局替换窗口,点击右上角勾选正则,然后搜索框输入(#.*)即可,然后点击replaceall去掉所有注释2去掉单个文件注释ctrl+f

    2022年8月26日
    6
  • 关于 python 的缩进「建议收藏」

    关于 python 的缩进「建议收藏」python对缩进是敏感的,而大多教程对应缩进也只是几句话带过,对新手十分不友好,本文就把python常见的缩进问题做了一些整理。

    2022年4月19日
    72

发表回复

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

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