Python clipboard method, python clipboard
You can use the clipboard to automatically copy and paste the code. (Windows)
Import sysimport OS. pathimport win32clipboard as w import win32conimport win32apidef getText (): # Read clipboard w. openClipboard () d = w. getClipboardData (win32con. CF_TEXT) w. closeClipboard () return ddef setText (aString): # Write to clipboard w. openClipboard () w. emptyClipboard () w. setClipboardData (win32con. CF_TEXT, aString) w. closeClipboard () if _ name __= = '_ main _': a = "hello" setText () # write "hello" to the clipboard # automatically paste the content in the clipboard win32api. keybd_event (17,0,) # The key code of ctrl is 17 win32api. keybd_event (,) # The key code of v is 86 win32api. keybd_event (86,0, win32con. KEYEVENTF_KEYUP, 0) # Release the win32api button. keybd_event (17,0, win32con. KEYEVENTF_KEYUP, 0) win32api. keybd_event (,) # Enter's key code is 13 win32api. keybd_event (13,0, win32con. KEYEVENTF_KEYUP, 0)
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.