【Python】win32api的打开程序及按键操作、win32clipboard的剪切板操作

import time

import win32api
import win32clipboard
import win32con

timespan = 0.3

if __name__ == ‘__main__‘:
    win32api.ShellExecute(0, ‘open‘, ‘notepad.exe‘, ‘‘, ‘‘, 1)
    time.sleep(timespan)

    # 按下ctrl+v
    win32api.keybd_event(0x11, 0, 0, 0)
    win32api.keybd_event(0x56, 0, 0, 0)
    win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(timespan)

    # 按下ctrl+s
    win32api.keybd_event(0x11, 0, 0, 0)
    win32api.keybd_event(0x53, 0, 0, 0)
    win32api.keybd_event(0x53, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(timespan)

    filename = ‘dilexliu.log‘
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(filename)
    win32clipboard.CloseClipboard()
    time.sleep(timespan)

    # 按下ctrl+v
    win32api.keybd_event(0x11, 0, 0, 0)
    win32api.keybd_event(0x56, 0, 0, 0)
    win32api.keybd_event(0x56, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(0x11, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(timespan)

    # 按下回车
    win32api.keybd_event(0x0D, 0, 0, 0)
    win32api.keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(timespan)

【Python】win32api的打开程序及按键操作、win32clipboard的剪切板操作

上一篇:使用python发邮件


下一篇:宝塔Python项目设置及启动文件编辑