This code can use the Clipboard to complete automatic copy and paste functions.
Import Sysimport Os.pathimport Win32clipboard as W import Win32conimport win32apidef getText (): #读取剪切板 W. OpenClipboard () d = W.getclipboarddata (Win32con. Cf_text) W.closeclipboard () return ddef SetText (astring): #写入剪切板 W.openclipboard () W. EmptyClipboard () w.setclipboarddata (Win32con. Cf_text, astring) W.closeclipboard () if __name__== ' __main__ ': a= "Hello" setText (a) #将 "Hello" writing to clipboard # Automatically pastes the contents of the Clipboard win32api.keybd_event (17,0,0,0) #ctrl的键位码是17 win32api.keybd_event (86,0,0,0) #v的键位码是86 win32api.keybd_event (86,0,win32con. keyeventf_keyup,0) #释放按键 win32api.keybd_event (17,0,win32con. keyeventf_keyup,0) win32api.keybd_event (13,0,0,0) #Enter的键位码是13 win32api.keybd_event (13,0,win32con. keyeventf_keyup,0)
Python uses the Clipboard