1import pyperclip
2pyperclip.copy('The text to be copied to the clipboard.')
1import clipboard
2clipboard.copy("abc") # now the clipboard content will be string "abc"
3text = clipboard.paste() # text will have the content of clipboard
4
1# To use native Python directories, use:
2from subprocess import check_call
3
4# On windows use:
5def copy2clip(txt):
6 cmd='echo '+txt.strip()+'|clip'
7 return check_call(cmd, shell=True)
8
9# On Mac use:
10def copy2clip(txt):
11 cmd='echo '+txt.strip()+'|pbcopy'
12 return check_call(cmd, shell=True)
13
14# Then to call the function use:
15copy2clip('This is on my clipboard!')
1import clr
2import System
3from System.Threading import Thread, ThreadStart
4clr.AddReference("System.Windows.Forms")
5
6def SetText(text):
7 def thread_proc():
8 System.Windows.Forms.Clipboard.SetText(text)
9 t = Thread(ThreadStart(thread_proc))
10 t.ApartmentState = System.Threading.ApartmentState.STA
11 t.Start()
12SetText("Hello word")