queensoft Posted April 24, 2021 Share Posted April 24, 2021 $ret = Run($command, '', @SW_SHOW, 9) Sleep(100) ;Send("{DOWN}{UP}{DOWN}{DOWN}X{ENTER}") ;StdinWrite($ret, ????????????????? & "X" & @cr) How do I "convert" the Send command to correct StdinWrite parameter ? Thank you. Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 Hope this small piece of code that can help you: Global $hwnd = "C:\WINDOWS\system32\cmd.exe" Global $iEr = Run(@ComSpec & " /k " & '@echo Please wait', "", @SW_SHOW) Global $iCountW = 30 While WinExists($hwnd) $iCountW -= 1 If $iCountW < 1 Then Exit Sleep(500) WEnd Sleep(500) _SendToCmd("mkdir 1" & @CR) _SendToCmd("rmdir 1" & @CR) _SendToCmd("mkdir 2" & @CR) _SendToCmd("rmdir 2" & @CR) _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd(@CR) ; {ENTER} = @CR) _SendToCmd("exit"& @CR) Func _SendToCmd($key) Sleep(250) WinActivate($hwnd, "") WinActive($hwnd, "") Return Send($key) EndFunc ;==>_SendToCmd caramen 1 Regards, Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 Shouldn't WinActive be WinWaitActive instead ? Quote WinActive : Checks to see if a specified window exists and is currently active. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 (edited) 1 hour ago, Nine said: Shouldn't WinActive be WinWaitActive instead ? @Jos, i need help. I tested ! WinWaitActive The script will stop by the time set in the timeout variable, After the time is up the script checks for the existence of the window. I do not understand !!! I don't know if it's a bug or not! from: AutoIt (3.3.15.3) SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 Edited April 26, 2021 by VIP Regards, Link to comment Share on other sites More sharing options...
Developers Jos Posted April 26, 2021 Developers Share Posted April 26, 2021 Which part do you not understand about the timeout? The TimeOut is the Max waiting time, so the WinWaitActive() will either wait until that Window is active and continue or else wait the number of seconds defined in the TimeOut when it is greater than 0. Jos Trong 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...
Nine Posted April 26, 2021 Share Posted April 26, 2021 @VIP There is a couple of bugs in your code (I noticed when testing it). Here a functional version of your code : #include <Constants.au3> Global $hwnd = "C:\Windows\system32\cmd.exe" Global $iEr = Run(@ComSpec & " /k " & '@echo Please wait', "", @SW_SHOW) Global $iCountW = 30 While Not WinExists($hwnd) $iCountW -= 1 If $iCountW < 1 Then Exit MsgBox ($MB_SYSTEMMODAL, "", "Unable to lauch DOS console") Sleep(500) WEnd Sleep(500) _SendToCmd("echo 1" & @CR) _SendToCmd("echo 2" & @CR) _SendToCmd("echo 3" & @CR) _SendToCmd("echo 4" & @CR) _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd(@CR) ; {ENTER} = @CR) _SendToCmd("exit"& @CR) Func _SendToCmd($key) Sleep(250) WinActivate($hwnd, "") Local $t = WinWaitActive($hwnd, "", 2) ConsoleWrite ($t & @CRLF) Return Send($key) EndFunc ;==>_SendToCmd 1. Remember that using title, it is case sensitive 2. Your loop was checking the inverse Trong 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 Thanks Nine I didn't really notice that WinWaitActive is case sensitive. Thank you for the guidance. Global $hwnd = @ComSpec Global $iEr = Run(@ComSpec & " /k " & '@echo Please wait', "", @SW_SHOW) Global $iCountW = 30 Global $hwndX=WinWaitActive($hwnd,'',$iCountW) ConsoleWrite("Handle:"&$hwndX &" Error:"& @error & " Extended:"&@extended&"" &@CRLF) #cs While WinExists($hwnd) $iCountW -= 1 If $iCountW < 1 Then Exit Sleep(500) WEnd #ce Sleep(500) _SendToCmd("@echo 1" & @CR) _SendToCmd("@echo 2" & @CR) _SendToCmd("@echo 3" & @CR) _SendToCmd("@echo 4" & @CR) _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd(@CR) ; {ENTER} = @CR) _SendToCmd("exit"& @CR) Func _SendToCmd($key) Sleep(250) WinActivate($hwnd, "") Return Send($key) EndFunc ;==>_SendToCmd Regards, Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 Not only WinWaitActive but all win* functions are case sensitive. Unless you have WinTitleMatchMode set to a negative value. Trong 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 One final suggestion to your code. You could use ControlSend instead of Send. It would make your code much more robust that way. And it would alleviate the necessity of having the Console active... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 I have tested and with no success. I can't find controlID on Console windows. Regards, Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 No need for a controlID, just leave it blank. It is working fine without it... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 2 minutes ago, Nine said: No need for a controlID, just leave it blank. It is working fine without it... s Global $hwnd = @ComSpec Global $iEr = Run(@ComSpec & " /k " & '@echo Please wait', "", @SW_SHOW) Global $iCountW = 30 Global $hwndX=WinWaitActive($hwnd,'',$iCountW) ConsoleWrite("Handle:"&$hwndX &" Error:"& @error & " Extended:"&@extended&"" &@CRLF) #cs While WinExists($hwnd) $iCountW -= 1 If $iCountW < 1 Then Exit Sleep(500) WEnd #ce Sleep(500) _SendToCmd("@echo 1" & @CR) _SendToCmd("@echo 2" & @CR) _SendToCmd("@echo 3" & @CR) _SendToCmd("@echo 4" & @CR) _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd("{UP}") _SendToCmd(@CR) ; {ENTER} = @CR) _SendToCmd("exit"& @CR) Func _SendToCmd($key) Sleep(250) WinActivate($hwnd, "") ;Return Send($key) Return ControlSend($hwnd,'','','',$key) EndFunc ;==>_SendToCmd Why did the script not work, where did I go wrong? Regards, Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 9 minutes ago, VIP said: ControlSend($hwnd,'','','',$key) You have one too much blank in there : ControlSend($hwnd, '', '', $key Trong 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Trong Posted April 26, 2021 Share Posted April 26, 2021 🤣 My mistakes ^^ Regards, Link to comment Share on other sites More sharing options...
Gianni Posted April 26, 2021 Share Posted April 26, 2021 (edited) ... P.S. Just for the record. From the AutoIt help for the ControlSend command: Remarks: ..."ControlSend() is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend() should be way more reliable than a normal Send() - and yes it does send shift, ctrl, alt etc." ... Edited April 26, 2021 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Nine Posted April 26, 2021 Share Posted April 26, 2021 Don't worry about this remark. DOS console accept messages very well. As a proof : #include <Constants.au3> #include <SendMessage.au3> #include <WindowsConstants.au3> Global $hwnd = "C:\Windows\system32\cmd.exe" Global $iEr = Run(@ComSpec & " /k " & '@echo Please wait', "", @SW_SHOW) Global $iCountW = 30 While Not WinExists($hwnd) $iCountW -= 1 If $iCountW < 1 Then Exit MsgBox ($MB_SYSTEMMODAL, "", "Unable to lauch DOS console") Sleep(500) WEnd Sleep(500) $hwnd = WinGetHandle($hwnd) _SendMessage($hwnd, $WM_CHAR, 0X41, 0) _SendMessage($hwnd, $WM_CHAR, 0X42, 0) _SendMessage($hwnd, $WM_CHAR, 0X43, 0) Gianni 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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