signed

QiShunwang

“诚信为本、客户至上”

python实现自动打开文档,软件

2021/1/28 13:46:03   来源:

你是否有文档太多难以管理?
你是否向通过dos命令输入文档的简写名称直接打开?
哈哈哈哈哈哈,皮一下

首先确保电脑有pyautogui包

pip install pyautogui

python代码(全部)

只需要修改文档的位置即可

import os
import pyautogui
import time
import win32gui
import win32ui
from pywinauto.application import Application
import win32api
import win32con

#pyautogui.moveTo()将鼠标移动到指定位置
# time.sleep(6)
# pyautogui.click(clicks=2)#鼠标点击,实现鼠标双击

# win32api.ShellExecute(1,'open',r'D:\Xshell 7\Xshell.exe','', '',win32con.SW_SHOWMAXIMIZED)

def opendoc():
    os.startfile(r'E:\15-spark\笔记\Spark入门(3.0).docx')
    
def openscala():
    os.startfile(r'E:\14-scala\笔记\Scala.docx')

def openvm():
    # 打开vmwork
    win32api.ShellExecute(1,'open',r'D:\VMware\vmware.exe','', '',win32con.SW_SHOWMAXIMIZED)
    time.sleep(10)
    # 打开hadoop102
    pyautogui.moveTo(116,188)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(3)
    pyautogui.moveTo(286,149)
    time.sleep(0.1)
    pyautogui.click(clicks=1)
    time.sleep(0.1)
    # 打开hadoop103
    pyautogui.moveTo(116,204)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(3)
    pyautogui.moveTo(286,149)
    time.sleep(0.1)
    pyautogui.click(clicks=1)
    time.sleep(0.1)
    # 打开hadoop104
    pyautogui.moveTo(116,226)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(3)
    pyautogui.moveTo(286,149)
    time.sleep(0.1)
    pyautogui.click(clicks=1)
    time.sleep(0.1)
    pyautogui.moveTo(116,226)
    time.sleep(10)
    
def openSnipaste():
    os.startfile(r'E:\截屏工具Snipaste-1.11.3-x64\Snipaste.exe')
   
def opxshell():
    # 打开xshell
    win32api.ShellExecute(1,'open',r'D:\Xshell 7\Xshell.exe','', '',win32con.SW_SHOWMAXIMIZED)
    time.sleep(5)
    pyautogui.moveTo(100,229)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(0.5)
    pyautogui.moveTo(100,252)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(0.5)
    pyautogui.moveTo(100,268)
    time.sleep(0.5)
    pyautogui.click(clicks=2)
    time.sleep(0.5)

#界面显示选项
print("需要启动的应用: ")
print("a : 所有应用")
print("v : vmwark")
print("i : IDEA")
print("x : Xshell")
print("d : 文档笔记")
print("s : snipaste截图工具")
print("spark:spark文档")
print("scala:scala文档")

a = input("请选择: ")

while(True):
    if(a == 'x'):
        opxshell()
        break
    # 打开截图工具Snipaste
    if(a == 's'):
        openSnipaste()
        break      
# 文档类
    if(a == 'd'):
    # 打开当前学习的文档
        opendoc()
        break
        
    # 打开scala文档
    if(a == 'scala'):
        openscala()
        break
    if(a == 'a'):
        # opendoc()
        openvm()
        opxshell()
        break
    else:
        a = input("请重新选择: ")
    

# time.sleep(5)
# win32api.keybd_event(18,0,0,0)
# win32api.keybd_event(32,0,0,0) 
# time.sleep(0.1) 
# win32api.keybd_event(88,0,0,0) 
# time.sleep(2)
# win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
# win32api.keybd_event(32,0,win32con.KEYEVENTF_KEYUP,0)
# win32api.keybd_event(88,0,win32con.KEYEVENTF_KEYUP,0)

鼠标位置

需要模拟鼠标,所以需要读取鼠标位置,

#测试鼠标的位置
import pyautogui
import time
#循环执行pyautogui.position()获取不同位置坐标
while True:
    print(pyautogui.position())
    time.sleep(1)#设置打印的时间间隔