Jump to content

ControlSend to multiple windows


Recommended Posts

Can you controlsend different keys to multiple windows at the same time?

E.g if i was automating something (like ctrlsend to firefox) i could open 3 firefox windows and make the time it takes to automate all my data by 1/3rd as 3 are running at once?

The only thing i think would be an issue is they are all going to have the same handle and since they are all opening the same site they will have the same title everytime..

Is there a way to set a firefox title? - i found a few addons but my proxy blocks them at work unfortunately.. -.-

Any other way to do this?

Edited by 13lack13lade
Link to comment
Share on other sites

Have a bat file, or script, call your actual script 3x.

Not familiar with the firefox functions, but _IE has _iecreate, which would make a distinct browser on each run.

Then, use the _IE functions, rather than controlsend, and they will all be standalone, and non conflicting.  They will manipulate the DOM, and not use sends, which require the window (generally) to be active, which means the scripts would be competing to make their window active.

I know there is a FF udf in the examples forum...look into that, and do the same.

Example of script 1:

For $i = 0 To 2
    Run (@AutoItExe & " /AutoIt3ExecuteScript test4.au3 " & $i)
Next

Example of Test4.au3:

#include <ie.au3>

If $CmdLine[0] = 1 Then
    $iPos = $CmdLine[1]
Else
    $iPos = 1
EndIf

$iWidth = @DesktopWidth/3
$iHeight = @DesktopHeight

$oIE = _IECreate()
$hIE = _IEPropertyGet($oIE,"hwnd")
WinMove($hIE,"",$iPos*$iWidth, 0, $iWidth, $iHeight)
_IENavigate($oIE, "google.com")

Sleep(2000)

$oObj = _IEGetObjById($oIE, "gbqfq")
_IEAction($oObj, "Focus")
_IEFormElementSetValue($oObj,"Do Some Search")

$oObj = _IEGetObjById($oIE, "gbqfba")
_IEAction($oObj, "Focus")
_IEAction($oObj, "click")
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Thanks for your response jdelaney... i am trying to articulate it at the moment...

Cant use functions to interact with elements as the webpage hasn't got unique identifiers like class, name, id for any of the buttons, input boxes etc ... unfortunately.

My understanding of controlsends is that it doesnt matter what state the window is in? that is what lead me to the question of if i can run multiple at once... since it doesnt matter what state the window is in.

Sorry im still very noob at programming.. 

Link to comment
Share on other sites

Nope, the sends can interact with eachother.  You can use controlsettext, and they will never interact, but send|controlsend may conflict.

Example:

For $i = 0 To 20
    Run (@AutoItExe & " /AutoIt3ExecuteScript test4.au3 " & $i)
Next

Uncomment the controlsend, and comment the set text...some of the notepads will open 'print' or 'save as' menus, because they are interacting with eachother...change to controlsettext, and everything goes fine:

#include <WinAPI.au3>

Local $hNotepad1,$hNotePad1Edit
$iPID = Run ("notepad")
While Not IsHWnd($hNotepad1)
    $a = WinList("[CLASS:Notepad]")
    For $i = 1 To UBound($a)-1
        Local $iCurrentPID
        _WinAPI_GetWindowThreadProcessId($a[$i][1],$iCurrentPID)
        If $iCurrentPID = $iPID Then
            $hNotepad1=$a[$i][1]
            ExitLoop
        EndIf
    Next
WEnd

While Not IsHWnd($hNotePad1Edit)
    $hNotePad1Edit = ControlGetHandle($hNotepad1,"",15)
WEnd

;~ ControlSend($hNotepad1,"",$hNotePad1Edit, "this notepad was created by your script=" & $CmdLine[1] & @CRLF)
ControlSetText($hNotepad1,"",$hNotePad1Edit, "this notepad was created by your script=" & $CmdLine[1] & @CRLF)

Look into my signature, and you can use XPath's to grab your object.  No unique ID's required...just make the xpath specific enough.

Remarks in ControlSend:

Remarks

ControlSend works in a similar way to Send but it can send key strokes directly to a window/control, rather than just to the active window.

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.

As mention in the Send help the keyboard that send different chars when in CAPS LOCK and using the Shift Key cannot be simulated. An example is the Czech Keyboard. A good workaround is to use the ControlSetText.

The control might first need to be given focus with the ControlFocus command, specially when referencing an controlID created by the script itself.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...