erbizard Posted November 12, 2018 Posted November 12, 2018 Hi, I want to know if it's possible to make a windows focus by his PiD (I've already seen many post on the forum that discuss about this topics but no one respond to what i want to do) actually this is my code test.au3 json #include <json.au3> $data = fileread("test.json") $object = json_decode($data) Global $i = 0 While 1 $product_id = json_get($object, '.test1[' & $i & ']') If @error Then ExitLoop $i += 1 WEnd ConsoleWrite('Number of records:' & $i & @CRLF) local $Pids[$i] for $y = 0 To $i - 1 ConsoleWrite('passage n°' & $y & @CRLF) ConsoleWrite('y' & $y & @CRLF) ConsoleWrite('i' & $i & @CRLF) $Pids[$y] = Run("notepad.exe", "") Sleep(200) WinSetState($Pids[$y], "", @SW_HIDE ) Next Sleep(800) for $y = 0 To $i - 1 ConsoleWrite('WinActivate de pid ' & $Pids[$y] & @CRLF) WinSetOnTop($Pids[$y], "", 1) sleep(300) Send("{Enter}") Send(json_get($object, '.test1[' & $y & '].id')) Send("{TAB}") Send(json_get($object, '.test1[' & $y & '].pw')) Send("!{ESC}") Next test.json { "test1":[ { "id": "Id1", "pw": "Pw1" }, { "id": "Id2", "pw": "Pw2" } ] } it work pretty well ! But the problem is this : I don't want to use the alt+esc shortcut to switch windows that my script opened and i want to know if it's possible to make the notepad opens as front window ? Thanks for your time, Sorry for bad English.
Nine Posted November 12, 2018 Posted November 12, 2018 WinSetState($Pids[$y], "", @SW_HIDE ) and WinSetOnTop($Pids[$y], "", 1) don't work with pid. They use win handles (or win titles). But the easiest way would be for you to grab the handles after the run commands instead of pids which, in your code, are useles... “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
erbizard Posted November 12, 2018 Author Posted November 12, 2018 Yeah, I know these two commands do nothing :/ I'm affraid about the WinGetHandle function, what append when multiples windows with the same name are opened ? Like in my code i'll make something like this, but in the 2nd / 3rd .. [n]th try, how the function will know what window to get ? for $y = 0 To $i - 1 ConsoleWrite('passage n°' & $y & @CRLF) ConsoleWrite('y' & $y & @CRLF) ConsoleWrite('i' & $i & @CRLF) Run("notepad.exe", "") $Handles[$y] = WinGetHandle("[CLASS:Notepad]") Next After some test, this function don't seem to be consitent. When I try to open 10+ notepad with this code, i got some duplicate in my handleList
Nine Posted November 12, 2018 Posted November 12, 2018 (edited) try using [ACTIVE] instead it will work like a charm each handle has its own number (a bit like pids) so once you have the list, there is no mistake possible... sleep awhile between run and wingethandle Edited November 12, 2018 by Nine “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
AdamUL Posted November 12, 2018 Posted November 12, 2018 You can also try using WinGetProcess to check the PID returned matches the PID returned by Run. Adam
erbizard Posted November 12, 2018 Author Posted November 12, 2018 Perfect, That work pretty well ! Thanks for your help guys !
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