Can python access windows clipboard

M

MaHL

Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?

Thanks very much!
 
A

Ant

Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?

The following requires Mark Hammond's win32all package (http://
sourceforge.net/projects/pywin32/):

import win32clipboard, win32con, random

text = "Some text to stick on the clipboard"

win32clipboard.OpenClipboard()
win32clipboard.SetClipboardData(win32con.CF_TEXT, text)
win32clipboard.CloseClipboard()
 
G

Gabriel Genellina

Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?

Yes, using the pywin32 extensions that you can download from Sourceforge

py> from win32clipboard import *
py> OpenClipboard()
py> EmptyClipboard()
py> SetClipboardText("Hello from Python!")
11272196
py> CloseClipboard()

Ctrl-v: Hello from Python!
 
M

Michael Hoffman

MaHL said:
Can I use python to copy something(like a string) to the clipboard, so
that I can paste it somewhere else. Is there a way to do this?

If you're using Cygwin Python you can just open /dev/clipboard and work
on that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top