python 窗体句柄_Python pyautogui窗口句柄(Python pyautogui window handle)

本文探讨如何使用pyautogui获取窗口句柄,确保在特定窗口执行点击操作。当窗口失去焦点时,先将其聚焦再执行操作。同时提到了pywinauto库作为替代方案,支持更复杂的窗口交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python pyautogui窗口句柄(Python pyautogui window handle)

使用pyautogui是否有办法获取窗口的句柄,以便我可以确保只在该窗口上执行单击? 换句话说,如果我的窗口没有聚焦,则不会发生单击。 此外,如果我的窗口没有聚焦,那么我将其置于焦点,然后执行操作。

是否有任何其他支持此类功能的Python模块?

Using pyautogui is there a way to get a handle to a window so that I can ensure that a click is performed on that window only? In other words, if my window isn't in focus, then the click does not occur. Additionally, if my window isn't in focus then I bring it into focus and then perform the actions.

The way to identify a window could be an ID, window title etc similar to this https://autohotkey.com/docs/commands/WinGet.htm

Is there any other Python module that supports this kind of functionality?

原文:https://stackoverflow.com/questions/43785927

2019-12-06 07:36

相关问答

也许你没有正确使用click功能。 查看函数定义: 单击(x =无,y =无,clicks = 1,interval = 0.0,button ='left',duration = 0.0,tween =,pause = None,_pause = True) 使用pyautogui.click(650, 200, 10)你说x = 650,y = 200,点击= 10。 我想你想说pyautogui.click(650, 200, interval=10) 。 The problem may h...

是否有任何其他支持此类功能的Python模块? https://pywinauto.github.io https://pywinauto.readthedocs.io/en/latest/#some-similar-tools-for-comparison Is there any other Python module that supports this kind of functionality? https://pywinauto.github.io https://pywinauto....

这可能是因为你正在从Python 2.x shell中尝试它。 请在python3 shell上试试这个命令并尝试导入相同的命令。 It might be because you're trying it from a python 2.x shell. Instead try this command on a python3 shell and try importing the same.

看起来你需要导入ImageGrab from PIL import ImageGrab

Looks like you need to import ImageGrab from PIL import ImageGrab

我不确定SO上的格式设置是否正确(您的评论显示为关键字),但看起来您的while True语句之外有if语句。 如果是这种情况,它将永远不会被执行(或检查)。 #! python3

import pyautogui

import time

pyautogui.screenshot('first.png')

check = pyautogui.locateCenterOnScreen('first.png')

print(check)

while True:

pyautogui.scree...

要安装PyAutoGUI,请从PyPI和依赖项安装pyautogui软件包。 在Windows上,这是: C:Python34pip.exe install pyautogui

To install PyAutoGUI, install the pyautogui package from PyPI and dependencies. On Windows, this is: C:Python34pip.exe install pyautogui

Pyautogui的源代码 def _sendMouseEvent(ev, x, y, dwData=0):

assert x != None and y != None, 'x and y cannot be set to None'

width, height = _size()

convertedX = 65536 * x // width + 1

convertedY = 65536 * y // height + 1

ctypes.windll.u...

你可以修补pyautogui内部。 测试'xvfb'后端。 import os

from pyvirtualdisplay import Display

import pyautogui

import Xlib.display

v_display = Display(visible=1, size=(1600,900))

v_display.start() # this changes the DISPLAY environment variable

# sadly, pyautogui do...

我得到这个错误,发现它仍然执行这个点击: try:

pyautogui.click()

except:

print "Error-carrying on anyway"

或者,如果您不希望它打印任何东西: try:

pyautogui.click()

except:

pass

I got this error and found that it still performs the click- try this: try:

pyautogui.clic...

如果您需要可移植且可靠的解决方案,则必须找到支持辅助功能技术的库,以便按文本访问GUI元素。 基本技术是: Win32 API,MS UI自动化(Windows) AT-SPI(Linux) Apple Accessibility API(MacOS) 有几个开源GUI自动化库支持其中一些技术(通常为1或2)。 Python解决方案: Windows上的pywinauto (Win32 API和MS UIA,请参阅入门指南 ) Linux上的pyatspi2 MacOS上的pyatom Stack...

相关文章

当前屏幕分辨率为1280*1024,IE7下使用 window.open('', '', 'left

...

1、下载redis的window版本 下载地址: https://github.com/Service

...

Python 编程语言具有很高的灵活性,它支持多种编程方法,包括过程化的、面向对象的和函数式的。但最重

...

python2和python3的区别,1.性能 Py3.0运行 pystone benchmark的速

...

python的官网:http://www.python.org/ 有两个版本,就像struts1和st

...

Python的文件类型 Python有三种文件类型,分别是源代码文件、字节码文件和优化代码文件

源代

...

好久没有写了,还不是近期刚过的期末考试和期中考试 最近因为一个微信公众平台大赛在学phthon 找了本

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值