Mouse can only interact with the active Window, the one who has the focus, so forget that option.
You can use ControlSend or _GuiCtrlEdit_xxxxx functions to send messages to the window.
An Option is to move the caret (blinking cursor) on the notepad Window meanwhile it is minimized or not focused and then use these functions:
;notepad.au3 by Lepes
;Creado con ISN Studio AutoIt v. 1.14
;*****************************************
;Make this script high DPI aware
;AutoIt3Wrapper directive for exe files, DllCall for au3/a3x files
#AutoIt3Wrapper_Res_HiDpi=y
If not @Compiled then DllCall("User32.dll", "bool", "SetProcessDPIAware")
#include <GuiEdit.au3>
; using Standard UDF
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
Example_External()
Func Example_External()
Local $s_Text = 'Find And Replace Example with AutoIt ' & FileGetVersion(@AutoItExe) & @CRLF & _
"this is a test" & @CRLF & _
"this is only a test" & @CRLF & _
"this testing should work for you as well as it does for me"
Local $hTitle, $hHandle
Local $sTitle = "[CLASS:Notepad]"
; Run("notepad.exe", "", @SW_MAXIMIZE)
;Wait for the window "Untitled" to exist
;WinWait($sTitle)
; Get the handle of a notepad window
$hTitle = WinGetHandle($sTitle)
If @error Then
MsgBox($MB_SYSTEMMODAL, "Error", "A Notepad window must be opened and minimized before running this script")
Else
$hHandle = ControlGetHandle($hTitle, "", "Edit1")
If @error Then
MsgBox($MB_SYSTEMMODAL, "Error", "Could not find the correct control")
Else
; Set all text
_GUICtrlEdit_SetText($hHandle, $s_Text)
;_GUICtrlEdit_Find($hHandle, True)
; move Caret inside the window.
_GUICtrlEdit_SetSel($hHandle, 15, 15)
; if the second parameter is greater than the first one, text will be highlighted
;how many lines has the text?
$ilines = _GUICtrlEdit_GetLineCount($hHandle)
MsgBox(0, "", "notepad has " & $ilines & " lines")
; selecting 5 characters
_GUICtrlEdit_SetSel($hHandle, 15, 20)
MsgBox(0, "", "Don't click on Accept button, activate Notepad and check that some text is selected!" & @CRLF & "Then click Accept button to continue")
; Replace selected text
; all 5 characters already selected, will be replaced
_GUICtrlEdit_ReplaceSel($hHandle, "-TEXT_REPLACED-")
; moving caret to position 40
; keep in mind that -TEXT_REPLACED- already count!!
_GUICtrlEdit_SetSel($hHandle, 40, 40)
; There is not selected text so new text will be inserted at position 40
_GUICtrlEdit_ReplaceSel($hHandle, "-TEXT INSERTED-")
;get all text from the Notepad Window:
$sAllText = _GUICtrlEdit_GetText($hHandle)
MsgBox(0, "", "whole new text from notepad is: " & @CRLF & $sAllText)
$sLine = _GUICtrlEdit_GetLine($hHandle, 0) ; first line is Zero
MsgBox(0, "", "First Line (zero based) is : " & @CRLF & $sLine)
; moving caret to position 90
; keep in mind that -TEXT_REPLACED- already count!!
_GUICtrlEdit_SetSel($hHandle, 90, 90)
; What line number am I?
$iline = _GUICtrlEdit_LineFromChar($hHandle, 90) + 1
MsgBox(0, "", "I am at line " & $iline & @CRLF & "From now on, click on Notepad title bar to activate and see where is the caret position." & @CRLF & "Don't click inside text area")
$ichar = _GUICtrlEdit_LineIndex($hHandle)
MsgBox(0, "", "Caret position is now at position " & $ichar)
; Append text to the end of the file, automatically changes the position of the caret
_GUICtrlEdit_AppendText($hHandle, ".--New text added to the end")
$ichar = _GUICtrlEdit_LineIndex($hHandle)
MsgBox(0, "", "Caret position is now at position " & $ichar)
EndIf
EndIf
EndFunc ;==>Example_External
There are more _GuiCtrlEdit_xxxx functions, take a look.