llssff Posted October 27, 2021 Posted October 27, 2021 My current script: ``` $notepadWindow = RunWait('notepad.exe') ControlSend($notepadWindow, "Edit1", "", "abcde") WinSetState($notepadWindow, "", @SW_MINIMIZE) ``` I can't seem to get these three lines to work. Its supposed to run a notepad window, then enter "abcde", followed by minimizing it. Currently it just opens and nothing happens. What am I doing wrong here?
Subz Posted October 27, 2021 Posted October 27, 2021 You need to get the notepad handle, see WinGetHandle Run("notepad.exe") WinWait("[CLASS:Notepad]", "", 10) Local $hWnd = WinGetHandle("[CLASS:Notepad]") ControlSend($hWnd, "", "Edit1", "abcde") WinSetState($hWnd, "", @SW_MINIMIZE)
llssff Posted October 27, 2021 Author Posted October 27, 2021 Thank you for the reply. @Subz Is it possible for me to grab the handle from the result of Run? I am wondering because I might have multiple of the same class.
Subz Posted October 28, 2021 Posted October 28, 2021 You could use something like: Global $g_hWnd Global $g_iPID = Run("notepad.exe") ProcessWait($g_iPID, 5) Global $g_hWnd = _GetProcessHandle("[CLASS:Notepad]") If @error Then Exit MsgBox(4096, "Error", $g_hWnd) ControlSend($g_hWnd, "", "Edit1", "abcde") WinSetState($g_hWnd, "", @SW_MINIMIZE) Func _GetProcessHandle($_vWinTitle = "", $_sWinText = "") Local $aWinlist = WinList($_vWinTitle, $_sWinText) If @error Then Return For $i = 1 To $aWinlist[0][0] If WinGetProcess($aWinlist[$i][0], "") = $g_iPID Then Return SetError(0, 0, $aWinlist[$i][1]) Next Return SetError(1, 0, "No handle found") EndFunc
llssff Posted October 28, 2021 Author Posted October 28, 2021 Oh cool, I didn't know the PID was different from the handle. Gonna go try this. ty
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