def clipboardSet(self, text):
self.initKernel()
CF_UNICODETEXT = 13
GHND = 66
if text is None:
return
if isinstance(text, type('')):
text = str(text, 'mbcs')
bufferSize = (len(text) + 1) * 2
hGlobalMem = ctypes.windll.kernel32.GlobalAlloc(ctypes.c_int(GHND), ctypes.c_int(bufferSize))
ctypes.windll.kernel32.GlobalLock.restype = ctypes.c_void_p
lpGlobalMem = ctypes.windll.kernel32.GlobalLock(ctypes.c_int(hGlobalMem))
ctypes.cdll.msvcrt.memcpy(lpGlobalMem, ctypes.c_wchar_p(text), ctypes.c_int(bufferSize))
ctypes.windll.kernel32.GlobalUnlock(ctypes.c_int(hGlobalMem))
if ctypes.windll.user32.OpenClipboard(0):
ctypes.windll.user32.EmptyClipboard()
ctypes.windll.user32.SetClipboardData(ctypes.c_int(CF_UNICODETEXT), ctypes.c_int(hGlobalMem))
ctypes.windll.user32.CloseClipboard()
评论列表
文章目录