Search code examples
autoit

How to simulate paste(CTRL + V) using AUTO IT in Word Document


Objectives -

  1. Open the target app using AutoIy
  2. Take a printscreen (ALT + PRTSCREEN) of the opened app(step 1)
  3. Open a new word document
  4. Paste the screenshot on word document

Issue: I am able to complete the first two step, however I am not able to paste the screenshot in Word document.

Root Cause

I am able to take the print screen using SEND ("!{PRINTSCREEN}") and open word document using UDF _WORD_DOCADD, but I am not able to paste from clipboard. The issue is, when I am using WinWaitActive to activate the document, the document is still not active and hence SEND ("^V") is not working.


Solution

  • I found a way to solve my problem. Steps followed are -

    1. Simulate ALT + PRNTSCRN
    2. Open Clipboard
    3. GetData from Clipboard as BITMAP
    4. Save the data as JPG using GDIPLUS_IMAGE_SAVETOFILE
    5. Use DOCADD to open new document and _Word_DocPictureAdd to save the image to word document.