Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copying and pasting from/to clipboard with python/win32

I downloaded the win32 for python 2.6 from this site.

This is the code to get/set the clipboard.

def test():
    OpenClipboard() 
    d=GetClipboardData(win32con.CF_TEXT) # get clipboard data
    SetClipboardData(win32con.CF_TEXT, "Hello") # set clipboard data
    CloseClipboard()

if __name__ == '__main__':
    if sys.platform == 'win32':
        from win32clipboard import *
        import win32gui, win32con
        test()

It works well with GetClipboarData, but SetClipboardData doesn't seem to work, as when I run the test(), I expect to get "hello" with ^V, but something that I copied before.

What might be wrong?

like image 829
prosseek Avatar asked Dec 21 '22 22:12

prosseek


1 Answers

To put data in the clipboard, you want to open the clipboard, then call EmptyClipboard before SetClipboardData.

like image 174
Jerry Coffin Avatar answered Dec 24 '22 12:12

Jerry Coffin