Dsmoeg999 Posted April 6, 2023 Share Posted April 6, 2023 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 More sharing options...
Solution ioa747 Posted April 6, 2023 Solution Share Posted April 6, 2023 (edited) MouseMove ( x, y [, speed = 10] ) the parameter $hWnd must go away Edited April 6, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 This moves the mouse in the currently active window. but I am looking to move the mouse in an inactive or minimized window.It seems to me that this is not the way to do it. Link to comment Share on other sites More sharing options...
Developers Jos Posted April 6, 2023 Developers Share Posted April 6, 2023 Why do you think you can at all or is that an assumption? Dsmoeg999 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 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 Dsmoeg999 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 Sorry you are right it does work but what I have noticed is that it also moves the mouse on the currently active screen is there any way to avoid this? Link to comment Share on other sites More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 in what I did post? I did not understand, can't find the notepad? I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 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 More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 36 minutes ago, Dsmoeg999 said: and you have another window open do you have more than one notepad open? I don't have a picture. Give me titles from the windows I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 Yes i have the editor Open SciTE i execute the code with F5 So thats my main window Link to comment Share on other sites More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 and the mouse goes to the notepad. is this what we are asking for? I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 No, what I am saying is that the mouse that is in the code editor should not move, the movement should only be done in notepad. Link to comment Share on other sites More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 (edited) how many mouse do you have? maybe the focus? Local $hWnd = WinWait("[CLASS:Notepad]") ControlFocus($hWnd, "", "Edit1") edit: what do you want to do, what do you have in mind, give me a scenario Edited April 6, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 6, 2023 Author Share Posted April 6, 2023 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 More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 (edited) the mouse inside the minimized window cannot move, and by simply clicking it, it will get focus and be activated Edited April 6, 2023 by ioa747 Dsmoeg999 1 I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted April 6, 2023 Share Posted April 6, 2023 (edited) you can send text inside the minimized window Local $hWnd = WinWait("[CLASS:Notepad]") ControlSend($hWnd, "", "Edit1", "string") or keys Local $hWnd = WinWait("[CLASS:Notepad]") ControlSend($hWnd, "", "Edit1", "{DOWN 3}") Edited April 6, 2023 by ioa747 Dsmoeg999 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Lepes Posted April 7, 2023 Share Posted April 7, 2023 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: expandcollapse popup;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. Dsmoeg999 1 Link to comment Share on other sites More sharing options...
Dsmoeg999 Posted April 7, 2023 Author Share Posted April 7, 2023 Thanks guys if I understand correctly that option is not viable is good to know. Best regards Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now