Copy and paste using Python commands

Asked

Viewed 2,625 times

2

I need to know how to make a copy of any text on the screen, simulating the mouse action. For the mouse, I’m using Pyautogui, running the actions. I need to save the copied content and store that information in a variable in order to future use. There is a way to do this ?

  • Can you copy the content? with Pyautogui

  • Good morning, Ewerton. Yes, I can. I can already select a region and copy using the Ctrl+c shortcut. Only " Paste" this information into a variable is missing .

  • All right, so follow my answer there..

1 answer

2


You can use the clipboard together with the PyAutoGui.

Installation of the Clipboard: pip install clipboard
Can be used like this:

import clipboard
import pyautogui

pyautogui.doubleClick(290, 150)
pyautogui.hotkey('ctrl', 'c')
text = clipboard.paste()
print(text)
  • There is a way to clear the Clipboard before giving the copy bell ?

  • You mean leave him with nothing copied?

  • If that’s it, you can do it like this clipboard.copy("")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.