zoukankan      html  css  js  c++  java
  • python 操作剪切板

    python3 在使用网上找到的一些使用剪切板的片段时发现存在写入剪切板后乱码的情况, 研究后发现python3不能使用SetClipboardData方法, 要使用SetClipboardText

                
    import sys  
    import os.path  
    import win32clipboard as w    
    import win32con  
    import win32api  
    def getText():#读取剪切板  
        w.OpenClipboard()  
        d = w.GetClipboardData(win32con.CF_TEXT)  
        w.CloseClipboard()  
        return d  
    def setText(aString):#写入剪切板  
        w.OpenClipboard()  
        w.EmptyClipboard()  
        w.SetClipboardText(aString)  
        w.CloseClipboard()  
    if __name__=='__main__':  
        a="hello"  
        setText(a)#将“你好”写入剪切板  
        #自动粘贴剪切板中的内容  
        win32api.keybd_event(17,0,0,0)  #ctrl的键位码是17  
        win32api.keybd_event(86,0,0,0)#v的键位码是86  
        win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) #释放按键  
        win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)  
        win32api.keybd_event(13,0,0,0)#Enter的键位码是13  
        win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)  
  • 相关阅读:
    P2009 跑步
    P3916 图的遍历
    P2865 [USACO06NOV]路障Roadblocks
    P2820 局域网
    P2176 [USACO14FEB]路障Roadblock
    讨伐!数论
    网络流入门——EK算法
    最被低估的特质
    我的天哪我有博客了!
    Area POJ
  • 原文地址:https://www.cnblogs.com/sea-stream/p/10362984.html
Copyright © 2011-2022 走看看