1、模拟鼠标键盘操作

from pymouse import PyMouse
from pykeyboard import PyKeyboard

# 定义实例
mouse = PyMouse()
keyboard = PyKeyboard(

2、获取当前坐标值,点击,移动

复制代码
coordinate = mouse.position()
print(coordinate)

mouse.click(x=1215, y=386, button=1, n=1)
# x y :坐标位置
# button : 1表示左键,2表示右键
# n :点击次数,默认1次,2表示双击


# 鼠标移动到坐标x,y,获取屏幕尺寸
mouse.move(x=1000, y=300)
c = x_dim, y_dim = mouse.screen_size()
b = mouse.position()
复制代码

 3、获取窗口句柄,并将其最大化

复制代码
# 方法1
import win32gui

windows_list = []
win32gui.EnumWindows(lambda hWnd, param: param.append(hWnd), windows_list)
for window in windows_list:
    classname = win32gui.GetClassName(window)
    title = win32gui.GetWindowText(window)
    print(title)

# 方法2
from win32gui import *

titles = set()


def foo(hwnd, nouse):
    # 去掉下面这句就所有都输出了,但是我不需要那么多
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles.add(GetWindowText(hwnd))


EnumWindows(foo, 0)
# lt = [t for t in titles if t]
# 循环titles,如果t为真返回t,典型的Python列表推导式
lt = [] for t in titles: if bool(t) is True: lt.append(t) lt.sort() for t in lt: print(t) print(lt) # 方法3 # blog: https://blog.51cto.com/u_15072918/4107747 handle = win32gui.FindWindow(0, "192.168.110.208_7016_6865 - SecureCRT") # 根据已打开的窗口名称,获取句柄号 # 将窗口置顶 # blog: # https://www.dandelioncloud.cn/article/details/1513086501389942785 win32gui.SetForegroundWindow(handle) win32gui.SetWindowPos(handle, win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE | win32con.SWP_NOACTIVATE | win32con.SWP_NOOWNERZORDER | win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE) # 设置为当前活动窗口,最大化需要 win32gui.SetForegroundWindow(handle) # 最大化窗口 win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE) # 调用窗口方法 import win32gui import win32con import win32com.client def get_all_hwnd(hwnd, mouse): if (win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd)): hwnd_map.update({hwnd: win32gui.GetWindowText(hwnd)}) hwnd_map = {} win32gui.EnumWindows(get_all_hwnd, 0) for h, t in hwnd_map.items(): if t: if t == '192.168.110.208_7016_6865 - SecureCRT': # h 为想要放到最前面的窗口句柄 print(h) win32gui.BringWindowToTop(h) shell = win32com.client.Dispatch("WScript.Shell") shell.SendKeys('%') # 被其他窗口遮挡,调用后放到最前面 win32gui.SetForegroundWindow(h) # 解决被最小化的情况 win32gui.ShowWindow(h, win32con.SW_MAXIMIZE)
复制代码

 

4、后期补充

posted on   Star*S  阅读(701)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示