湖上湖
您还可以使用ctypes进入Windows API并避免使用庞大的pywin32软件包。这就是我使用的(借口可怜的风格,但想法就在那里):import ctypes# Get required functions, strcpy..strcpy = ctypes.cdll.msvcrt.strcpy
ocb = ctypes.windll.user32.OpenClipboard # Basic clipboard functionsecb = ctypes.windll.user32.EmptyClipboardgcd = ctypes.windll.user32.GetClipboardDatascd = ctypes.windll.user32.SetClipboardDataccb = ctypes.windll.user32.CloseClipboardga = ctypes.windll.kernel32.GlobalAlloc # Global memory allocationgl = ctypes.windll.kernel32.GlobalLock # Global memory Lockinggul = ctypes.windll.kernel32.GlobalUnlockGMEM_DDESHARE = 0x2000def Get():
ocb(None) # Open Clip, Default task
pcontents = gcd(1) # 1 means CF_TEXT.. too lazy to get the token thingy...
data = ctypes.c_char_p(pcontents).value #gul(pcontents) ?
ccb()
return datadef Paste(data):
ocb(None) # Open Clip, Default task
ecb()
hCd = ga(GMEM_DDESHARE, len(bytes(data,"ascii")) + 1)
pchData = gl(hCd)
strcpy(ctypes.c_char_p(pchData), bytes(data, "ascii"))
gul(hCd)
scd(1, hCd)
ccb()