pyautogui compare result CTRL+V

Asked

Viewed 1,260 times

0

I have the following code

import pyautogui

pyautogui.moveTo(612, 269)
pyautogui.doubleClick()
copiar = pyautogui.hotkey('ctrl', 'c')
colar = pyautogui.hotkey('ctrl', 'v')
resultado = colar
print(resultado)

however my print is returning "None". I know I could show the result of CTRL+V direct, but I want to make a repeat structure with the conditional

carregando = 'carregada '
pyautogui.moveTo(612, 269)
pyautogui.doubleClick()
copiar = pyautogui.hotkey('ctrl', 'c')
colar = pyautogui.hotkey('ctrl', 'v')
resultado = colar
if copiar == carregando:
  copiar = pyautogui.hotkey('ctrl', 'c')
  • What exactly are you trying to do? The pyautogui.hotkey line does not return true or false, so this comparison you are trying to make will never work.

  • Thanks for the answer. So I need to know if the content inside my Ctrl+v equals "loaded". If it is the same, you should continue copying and pasting that specific point. If it is not the same, it will pass to another command.

1 answer

0


Looking at the hotkey method of the pyautogui class it is possible to verify that it does not returns nothing, Soon your comparison above won’t work.

I suggest taking the value that was copied to the clipboard (Clipboard) and comparing whether it was loaded or not.

Using the library Tkinter (Python 2) or Tkinter (Python 3)

import tkinter as tk
r = tk.Tk()
dado_copiado = r.clipboard_get()

Or using the win32clipboard library

import win32clipboard
dado_copiado = win32clipboard.GetClipboardData()
  • Thanks for your help. And how do I compare what I have inside Ctr+v? I need to know if the content inside my Ctrl+v is equal to "loaded". If it is the same, you should continue copying and pasting that specific point. If it is not the same, it will pass to another command.

  • I still don’t know exactly what you’re programming. If you want to take the content that was copied to the Clipboard and compare whether the data was "loaded" using Ctrl+C, you can use the Tkinter library.

  • I could compare the output of my Ctrl+C with the yet of some variable?

Browser other questions tagged

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