def CopyToClipboard(string):
 hWnd = lib.GetConsoleWindow()
 if lib.OpenClipboard(hWnd):
  cstring = ffi.new('char[]', string)
  size = ffi.sizeof(cstring)
  hGlobal = lib.GlobalAlloc(lib.GMEM_MOVEABLE, size)
  buffer = lib.GlobalLock(hGlobal)
  lib.memcpy(buffer, cstring, size)
  lib.GlobalUnlock(hGlobal)
  res = lib.EmptyClipboard()
  res = lib.SetClipboardData(lib.CF_TEXT, buffer)
  lib.CloseClipboard()

def CopyToClipboard ( string ) : hWnd = lib . GetConsoleWindow ( ) if lib . OpenClipboard ( hWnd ) : cstring = ffi . new ( 'char[]' , string ) size = ffi . sizeof ( cstring ) hGlobal = lib . GlobalAlloc ( lib . GMEM_MOVEABLE , size ) buffer = lib . GlobalLock ( hGlobal ) lib . memcpy ( buffer , cstring , size ) lib . GlobalUnlock ( hGlobal ) res = lib . EmptyClipboard ( ) res = lib . SetClipboardData ( lib . CF_TEXT , buffer ) lib . CloseClipboard ( )
use win32 api to copy string to the clipboard .