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)
    
    
  • 相关阅读:
    第五章:向量运算
    第四章:向量
    第三章:多坐标系
    近期一些学习的随笔
    2020高考游记
    寒假集训好题记录
    STL基本用法的一些记录
    2020暑假集训做题记录——数据结构
    2020.12.13~2020.12.20做题记录
    2020.11.30~2020.12.6 做题记录
  • 原文地址:https://www.cnblogs.com/dilex/p/15211427.html
Copyright © 2011-2022 走看看