Jump to content

Recommended Posts

Posted

 

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.

Posted

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... 

Posted

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 

Posted (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 :yawn:

Edited by Nine

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
×
×
  • Create New...