Accessing clipboard through software built on Python

Michael Torrie torriem at gmail.com
Sat Oct 27 11:20:07 EDT 2018


Couple of questions:
On 10/27/2018 07:17 AM, Musatov wrote:
> I am wondering if Python could be used to write a program that allows:
> 
> 1. Highlight some text
> 2. Ctl+HOTKEY1 stores the string of text somewhere as COPIEDTEXT1

This text comes from where?  Another application?

> 3. Highlight another string of text
> 4. Ctl+HOTKEY1 stores another string of text somewhere as COPIEDTEXT2
> 
> THEN
> 
> 5. Ctl+HOTKEY2 pastes COPIEDTEXT1

Gets pasted where?

> 6. Ctl+HOTKEY2 pastes COPIEDTEXT2

As far as I know it's not possible for an application to directly yank
highlighted text from another application.  The first application would
have to first copy that text to the clipboard (Control-C in that app)
and then the second application could grab it from the clipboard
(ctrl-hotkey1) and then store it in its own variables.  Ctrl-hotkey2
could then push the text back into the clipboard and then you can ctrl-V
paste it in the other application.  This type of functionality is known
often found in clipboard manager programs.

> I found "pyperclip" and "Tkinter" but I don't know where to start.
Here's another file that demonstrates accessing the clipboard on the
Linux, Mac, and Windows:

https://github.com/Shizmob/clippy/blob/master/clip.py

As for the hotkey stuff, that's also dependent on the operating system.
Google for something like "python global hotkey linux" to get an example
of how to implement that.



More information about the Python-list mailing list