zoukankan      html  css  js  c++  java
  • 【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 连接mysql数据库
    前端 之HTML基础
    MySQL 多键
    MySQL 存储引擎 字段类型 约束条件
    MySQL数据库的基础知识
    全局解释器和协程
    进程剩余部分和线程
    计算机网络体系结构整理-第三单元网络交换
    计算机网络体系结构整理-第二单元IP技术
  • 原文地址:https://www.cnblogs.com/dilex/p/15211427.html
Copyright © 2011-2022 走看看