#NEWLINE# def winSetClipboard( text ) : #NEWLINE# #INDENT# GMEM_DDESHARE = 8192 #NEWLINE# ctypes . windll . user32 . OpenClipboard ( 0 ) #NEWLINE# ctypes . windll . user32 . EmptyClipboard ( ) #NEWLINE# try : #NEWLINE# #INDENT# hCd = ctypes . windll . kernel32 . GlobalAlloc ( GMEM_DDESHARE , ( len ( bytes ( text ) ) + 1 ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# hCd = ctypes . windll . kernel32 . GlobalAlloc ( GMEM_DDESHARE , ( len ( bytes ( text , 'ascii' ) ) + 1 ) ) #NEWLINE# #UNINDENT# pchData = ctypes . windll . kernel32 . GlobalLock ( hCd ) #NEWLINE# try : #NEWLINE# #INDENT# ctypes . cdll . msvcrt . strcpy ( ctypes . c_char_p ( pchData ) , bytes ( text ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# ctypes . cdll . msvcrt . strcpy ( ctypes . c_char_p ( pchData ) , bytes ( text , 'ascii' ) ) #NEWLINE# #UNINDENT# ctypes . windll . kernel32 . GlobalUnlock ( hCd ) #NEWLINE# ctypes . windll . user32 . SetClipboardData ( 1 , hCd ) #NEWLINE# ctypes . windll . user32 . CloseClipboard ( )