Zulfiqaar
Zulfiqaar

Reputation: 633

Combining pyperclip copy-to-clipboard with pyautogui paste?

I want to paste some text loaded in from python into a browser field: Any method to load something into the clipboard, which I can then paste using Ctrl+V. Currently I see pyperclip.paste() only paste the text into the console, instead of where I want it. Pressing Ctrl+V after running pyperclip.copy('sometext') does nothing.

import pyautogui
import pyperclip

def click():
    try:
        pyautogui.click()
    except:
        pass

pyperclip.copy('sometext')
pyautogui.moveTo(4796, 714)
click()
pyperclip.paste()
pyautogui.hotkey('ctrl', 'v', interval = 0.15)

What am I doing wrong here? An alternative method would be just as welcome as a fix - preferably one that avoids using pyautogui.typewrite() as it takes a long time for lots of text

Update: seems to be a problem with pyperclip.copy('sometext') not putting or overwriting 'sometext' into the clipboard. the pyperclip paste function works as it should, and so does the pyautogui Ctrl+V

Upvotes: 6

Views: 30759

Answers (2)

theshape
theshape

Reputation: 11

You could store it as a variable, then use typewrite to input/paste it out.

paste_data = pyperclip.paste()
pyautogui.typewrite(paste_data)

Upvotes: 0

Youssri Abo Elseod
Youssri Abo Elseod

Reputation: 781

Try using pyautogui.typewrite instead:

import pyautogui

def click():
    try:
        pyautogui.click()
    except:
        pass

pyautogui.moveTo(4796, 714)
click()
pyautogui.typewrite('sometext')

You can find useful information here.

Upvotes: 5

Related Questions