Jump to content

It is possible to move the mouse in an inactive window ?


Go to solution Solved by ioa747,

Recommended Posts

Hi guys I know that it is possible to move the mouse in an active window but I don't know if there is a function to move it in an inactive window.

$hWnd = WinGetHandle("Notepad")
MouseMove(1827,105,3,$hWnd)

This does not work because it does not accept that number of arguments.Does anyone know if there is a function or way to do this? Thank you and best regards

 

Link to comment
Share on other sites

no MouseMove(1827,105,3,$hWnd) move nothing is wrong,  give the error: MouseMove() [built-in] called with wrong number of args.

 

if it helps

If WinExists("[CLASS:Notepad]") Then
    Local $aPos = WinGetPos("[CLASS:Notepad]")
    ;[0]=X position ; [1]=Y position ; [2]=Width ; [3]=Height
    MouseMove($aPos[0] + 50, $aPos[1] + 50)
EndIf

 

I know that I know nothing

Link to comment
Share on other sites

What happens is that it moves the mouse also from the active window and the inactive one at the same time if you minimize notepad and you have another window open it also moves and what I want is that it only moves in the one I specify. 
 

$hWnd = WinGetHandle("Notepad")

To act only in that window allowing me to use the mouse in another window at the same time.
So I'm not sure if this is the way to do it or if you have an alternative method to do this.

To give an example Controlsend sends a key to a particular window and nothing else.

Link to comment
Share on other sites

I only have one mouse. My objective is to have the notepad window minimized and to make a mouse movement inside the notepad so that it is positioned in the point of the coordinates that I put it, without changing the position of the mouse while I am in another window. Maybe this that I say can not be done but I had this question. If you look with the example that you have given me the mouse moves in the window that you are looking at the moment and I am only looking for it to move in the minimized one. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...