当前位置: 首页 > news >正文

2023-12-27 Python PC获取鼠标位置,移动鼠标到相应的位置 定时自动模拟鼠标点击,用于简单测试app用

一、核心源码如下:

import pyautogui
import timepyautogui.moveTo(600, 800)
for i in range(20):time.sleep(0.1)x, y = pyautogui.position()print("mouse position:", x, y)pyautogui.click()

二、定时自动模拟鼠标点击,模拟键盘按键

import pyautogui
import datetime
import time
import os
import win32gui,win32con
from win32 import win32api, win32gui, win32print
from win32.lib import win32con
import math
from colorama import Fore,Back,Style
import psutil
import tkinter as tk
import pygetwindowmem = psutil.virtual_memory()
# 系统总计内存
zj = float(mem.total) / 1024 / 1024 / 1024
# 系统已经使用内存
ysy = float(mem.used) / 1024 / 1024 / 1024# 系统空闲内存
kx = float(mem.free) / 1024 / 1024 / 1024R =float(mem.used) * 100 / float(mem.total)
"""获取真实的分辨率"""
hDC = win32gui.GetDC(0)
width = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)  # 横向分辨率
height = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)  # 纵向分辨率
print(width)
print(height)window = tk.Tk()
hwnd_title = {}def get_all_hwnd(hwnd, mouse):if (win32gui.IsWindow(hwnd)and win32gui.IsWindowEnabled(hwnd)and win32gui.IsWindowVisible(hwnd)):hwnd_title.update({hwnd: win32gui.GetWindowText(hwnd)})win32gui.EnumWindows(get_all_hwnd, 0)
for h, t in hwnd_title.items():if t :print (h, t)def setWindowTopmost(hwnd):'''将某个窗口设置为置顶窗口'''win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, width-350,height-175,350,119, win32con.SWP_SHOWWINDOW)#win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,0,0,45,3,win32con.SWP_NOSIZE|win32con.SWP_NOMOVE)#hwnd = win32gui.FindWindow(None,"Windows PowerShell")
#if hwnd != 0:#setWindowTopmost(hwnd)#os.popen('mode con cols=50 lines=3')
win = pygetwindow.getWindowsWithTitle('Py')[0]
win.size = (350, 119)
number=100#pyautogui.moveTo(0,100)
while True:#pyautogui.press('capslock')#pyautogui.press('numlock')#hwnd = win32gui.FindWindow(None,"Windows PowerShell")#setWindowTopmost(hwnd)#win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 0, 0, 0, 0,win32con.SWP_NOMOVE | win32con.SWP_NOACTIVATE |win32con.SWP_NOOWNERZORDER | win32con.SWP_SHOWWINDOW | win32con.SWP_NOSIZE)time.sleep(1.0)os.system('cls')current_time = datetime.datetime.now()timestamp = current_time.strftime('%Y-%m-%d %H:%M:%S')timestamp = timestamp + '.'+str(current_time.microsecond)[0:3]#print("" + str(timestamp))x, y = pyautogui.position()print("mouse position:", x, y)if number > 12:pyautogui.press('numlock')win.moveTo(width-350, height-175-number)time.sleep(0.9)win.moveTo(width-350, height-175)number=0pyautogui.moveTo(1212, 676)pyautogui.click()else:number=number+1print (Fore.GREEN + str(timestamp) + " Memory:",'%d%%' % R)

三、参考文章

Python中鼠标的位置获取方法_笔记大全_设计学院

用Python制作一个自动点击器,三种模块都可以_鼠标自动点击脚本-CSDN博客

http://www.lryc.cn/news/268633.html

相关文章:

  • 如何解决服务器CA证书过期的问题
  • 计算机基础面试题总结
  • 【算法练习】leetcode链表算法题合集
  • 2023.12.28每日一题
  • 231227-9步在RHEL8.8配置本地yum源仓库
  • 5. 创建型模式 - 单例模式
  • 机器学习之人工神经网络(Artificial Neural Networks,ANN)
  • GetLastError()详细介绍
  • 【unity3D-粒子系统】粒子系统主模块-Particle System篇
  • Windows搭建FTP服务器教学以及计算机端口介绍
  • 安防视频监控系统EasyCVR实现H.265视频在3秒内起播的注意事项
  • CNN实现对手写字体的迭代
  • docker学习笔记01-安装docker
  • 【《设计模式之美》】如何取舍继承与组合
  • 一步到位:用Python实现PC屏幕截图并自动发送邮件,实现屏幕监控
  • Spring Boot+RocketMQ 实现多实例分布式环境下的事件驱动
  • oracle ORA-01704: string literal too long ORACLE数据库clob类型
  • 微星主板强刷BIOS(以微星X370gaming plus 为例)
  • matlab 图像上生成指定中心,指定大小的矩形窗
  • ❀My学习小记录之算法❀
  • Hive-high Avaliabl
  • 码住!8个小众宝藏的开发者学习类网站
  • Postman常见问题及解决方法
  • ubuntu图形化登录默认只有guest session账号解决方法
  • 全国计算机等级考试| 二级Python | 真题及解析(1)
  • Java开发框架和中间件面试题(9)
  • 【ARMv8M Cortex-M33 系列 2 -- Cortex-M33 JLink 连接 及 JFlash 烧写介绍】
  • react pwa应用示例
  • python如何通过日志分析加入黑名单
  • RabbitMq知识概述