public
Created

Python Win32 clipboard usage

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Uses PyWin32 http://timgolden.me.uk/pywin32-docs/win32clipboard.html
import win32clipboard
 
def get_clipboard():
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data
 
def set_clipboard(text):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboard(text.encode('utf-8'),
win32clipboard.CF_TEXT)
win32clipboard.SetClipboard(unicode(text),
win32clipboard.CF_UNICODETEXT)
win32clipboard.CloseClipboard()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.