吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 321|回复: 4
收起左侧

[经验求助] 关于python多线程求助

[复制链接]
zhangjizhen1 发表于 2024-5-1 21:30
30吾爱币
研究了好几天了,始终搞不定,求求老哥救救孩子,
我这写的是通过窗口名字来获取多个窗口句柄,然后通过句柄来绑定这个窗口用后台的方式点击,
现在出现的问题是,运行成功
就是只有一个窗口释放了左键,其他都在一直按着不释放,问了GTP一天了也没搞定
[Python] 纯文本查看 复制代码
import threading
import logging
import win32api
import win32con
import win32gui
import time

logging.basicConfig(level=logging.DEBUG)

def 获取句柄(title):
    handles = []

    def callback(hwnd, _):
        window_title = win32gui.GetWindowText(hwnd)
        if title in window_title:
            handles.append(hwnd)
        return True

    win32gui.EnumWindows(callback, None)
    return handles

class HtTs:
    def __init__(self, handle):
        self.handle = handle
        self.lock = threading.Lock()  # 创建锁对象

    def dianji(self, x, y):
        with self.lock:  # 使用锁保护共享资源
            pos = win32api.MAKELONG(int(x), int(y))
            try:
                # 按下鼠标左键
                win32api.SendMessage(self.handle, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, pos)
                time.sleep(0.1)  # 等待一段时间
                # 松开鼠标左键
                win32api.SendMessage(self.handle, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, pos)
                logging.debug("Mouse button released.")
            except Exception as e:
                logging.error(f"Error sending mouse click message: {e}")

def print_window_handle(handle):
    try:
        logging.debug(f"Processing window with handle: {handle}")
        htts_instance = HtTs(handle)
        htts_instance.dianji(61, 879)
    except Exception as e:
        logging.error(f"Error in print_window_handle: {e}")


if __name__ == "__main__":
    window_title = "都玩"
    handles = 获取句柄(window_title)

    threads = []
    for handle in handles:
        t = threading.Thread(target=print_window_handle, args=(handle,))
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Allansoft 发表于 2024-5-3 22:46
是不是点击的区域在窗口外的问题所致
Allansoft 发表于 2024-5-3 22:53
手动拖动一个子窗口当鼠标移出窗口区域后释放鼠标,当鼠标再移到窗口区域内的时候,尽管鼠标已释放,但子窗口会仍然在拖动状态,直到再次点按一次鼠标,这说明窗口会忽略发生在窗口区域外的鼠标释放事件
 楼主| zhangjizhen1 发表于 2024-5-5 21:43
Allansoft 发表于 2024-5-6 19:55
是否有窗口设置了鼠标捕获
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-26 03:07

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表