0

I'm trying to find a way to paste in my OS in Python (not only the terminal).

This is my code to test but it only pastes in stdout.

import pyperclip
from time import sleep

pyperclip.copy('this is the text\nok\n')
n = 0
while n < 10:
    n += 1
    sleep(1)
    pyperclip.paste()

I know it should only paste in terminal, but I did not find any way to let Python paste in another application.

In my test (not real env), I use Notepadd and VSCode, and I see I can manually ctrl+v and clipboard works fine, but it does not automatically paste.

Saeed
  • 3,255
  • 4
  • 17
  • 36
  • Are you running this code in IDLE? Because according to the [documentation](https://pyperclip.readthedocs.io/en/latest/), `call pyperclip.paste() and the text will be returned as a string value`. It shouldn't be actually pasting the text anywhere, for me nothing shows up in a terminal because there's no `print()`. – shriakhilc Mar 27 '22 at 01:40
  • @shriakhilc yes. If I use `print(pyperclip.paste())`, it prints the texts. But my issue is python cannot automatically paste in another opened tab or program, like Notepad. – Saeed Mar 27 '22 at 01:41
  • @shriakhilc, thanks. Yes it answers me. I just saw `pyautogui` and was reading its docs. – Saeed Mar 27 '22 at 01:49
  • 1
    `pyperclip` is NOT for pasting to another program - only to paste from your code to clipboard and get from clipboard to your code. And if you see it in console then it has nothing to do with pasting - you simply get from clipboard and display/print it - and `print()` send it to console/terminal. – furas Mar 27 '22 at 04:23

0 Answers0