1

I am writing a python script that prepares a number of pieces of data to be posted into a web page and copies them to the clipboard using pyperclip. Currently I just have a time.sleep() statement between each one but based on latency and some slight variations in the web page response there may be other actions to be carried out (e.g. scroll down, clear a modal etc) before I am ready to paste the data. I run the risk of sometimes missing my 'window' for the paste but most of the time I am waiting for the sleep to finish and update the clipboard.

Instead of a fixed time period, it would be useful if I could make the python script pause until it detects the paste function and then load the clipboard with the next piece of data.

Note that the Ctrl+V will occur with the browser window having focus rather than the python script in case that makes a difference

I am using Chrome on Win-11 so an OS specific solution is fine for me. Also it does not need to be the Ctrl+V function (although this makes the most logical sense); any other trigger will do as long as it can't be confused and I can use pyautogui.keydown, keypress, keyup to trigger the Ctrl+V

Current Code:

      pyperclip.copy(EventTitle)
      os.system('cls')
      print('Title: ' + EventTitle)
      time.sleep(8)
      os.system('cls')
      pyperclip.copy(EventDescription)
      print('Description: \n\n' + EventDescription)
      time.sleep(8)
      os.system('cls')

basically I want to replace the time.sleep() with {wait for paste command}

Aaron Reese
  • 544
  • 6
  • 18
  • Looks like you need something to detect key presses. Maybe see if some answers [here](https://stackoverflow.com/questions/24072790/how-to-detect-key-presses) answer your question – smac89 Mar 26 '22 at 22:27
  • thanks smac89. I did find that post originally but it was 11pm and I had a bit to drink :) It looks overly complicated to capture keys with modifiers but I can probably use pyautogui.sendkeys('delete') to remove the single character just entered and then inrement the process to the next step. – Aaron Reese Mar 27 '22 at 09:17

0 Answers0