Python uses the Clipboard

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.