Jump to content

Recommended Posts

Posted

Hi! I have a little problem with function ControlSend. I would like to send a text to for example 2 windows with the same names. How to do that? Please help me

Heres my code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("TextSpike", 194, 266, 454, 270)
$Group1 = GUICtrlCreateGroup("Names of windows", 0, 8, 193, 257)
$Input1 = GUICtrlCreateInput("", 16, 32, 161, 21)
$Input2 = GUICtrlCreateInput("", 16, 64, 161, 21)
$Input3 = GUICtrlCreateInput("", 16, 96, 161, 21)
$Input4 = GUICtrlCreateInput("", 16, 128, 161, 21)
$Button1 = GUICtrlCreateButton("Set Hotkey", 32, 200, 129, 49, $WS_GROUP)
$Input5 = GUICtrlCreateInput("", 144, 160, 33, 21)
$Label1 = GUICtrlCreateLabel("Hotkey", 104, 160, 38, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)



While 1

        $1 = GuiCtrlRead($Input1)
        $2 = GuiCtrlRead($Input2)
        $3 = GuiCtrlRead($Input3)
        $4 = GuiCtrlRead($Input4)

        $5 = GuiCtrlRead($Input5)

        $msg = GUIGetMsg()

        Select

                Case $msg = $GUI_EVENT_CLOSE
                                        Exit
                Case $msg = $Button1
                                        HotKeySet($5, "Text")
        EndSelect
WEnd


Func ExitApp()
        Exit
EndFunc


Func Text()
        ControlSend($1, "", "[CLASS:Edit; INSTANCE:1]", "{Enter} text {Enter}")
        ControlSend($2, "", "[CLASS:Edit; INSTANCE:2]", "{Enter} text {Enter}")
        ControlSend($3, "", "[CLASS:Edit; INSTANCE:3]", "{Enter} text {Enter}")
        ControlSend($4, "", "[CLASS:Edit; INSTANCE:4]", "{Enter} text {Enter}")
EndFunc
Posted

Not exactly sure what you are looking for, and your script made it even more confusing.

So I will try to answer your question without looking at the script.

To Control windows that have the same title you will have to use the AutoIT window info tool and work with Handles.

here is an example of what too much coffee and late night boredom can do, it also displays how handles work.

at any point after declaration you can use the handle var to "control send" or control anything for that matter.

If this doesn't help or answer your question, please be more specific...good luck ;-)

ShellExecute("Notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd1 = WinGetHandle("[CLASS:Notepad]")
Sleep(300)
Send("My Handle is" & $hWnd1)
Sleep(300)
WinSetState($hWnd1, "", @SW_MINIMIZE)

Sleep(700)

ShellExecute("Notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd2 = WinGetHandle("[CLASS:Notepad]")
Sleep(300)
Send("My Handle is" & $hWnd2)
Sleep(300)
WinSetState($hWnd2, "", @SW_MINIMIZE)

Sleep(700)

ShellExecute("Notepad.exe")
WinWait("[CLASS:Notepad]")
Local $hWnd3 = WinGetHandle("[CLASS:Notepad]")
Sleep(300)
Send("My Handle is" & $hWnd3)
Sleep(300)
WinSetState($hWnd3, "", @SW_MINIMIZE)

WinSetState($hWnd1, "", @SW_RESTORE)
WinSetState($hWnd2, "", @SW_RESTORE)
WinSetState($hWnd3, "", @SW_RESTORE)


WinMove($hWnd1, "",830, 107, 400, 300,2)
WinMove($hWnd2, "",621, 519, 400, 300,2)
WinMove($hWnd3, "",82, 125, 400, 300,2)

WinSetState($hWnd1, "", @SW_HIDE)
WinSetState($hWnd2, "", @SW_HIDE)
WinSetState($hWnd3, "", @SW_HIDE)

WinSetState($hWnd1, "", @SW_SHOW)
WinSetState($hWnd2, "", @SW_SHOW)
WinSetState($hWnd3, "", @SW_SHOW)

WinMove($hWnd1, "",300, 250, 400, 300,2)
WinMove($hWnd2, "",400, 360, 400, 300,2)
WinMove($hWnd3, "",518, 258, 400, 300,2)

WinSetTrans($hWnd1, "", 100)
WinSetTrans($hWnd2, "", 200)
WinSetTrans($hWnd3, "", 25)

Sleep(1000)
WinFlash($hWnd2, "", 3)
Sleep(1000)

WinSetTrans($hWnd1, "", 255)
WinSetTrans($hWnd2, "", 255)
WinSetTrans($hWnd3, "", 255)

WinKill($hWnd1)
WinKill($hWnd2)
WinKill($hWnd3)
Posted (edited)

Thx for reply. Its something like this but I dont want to open the windows (These are opened already) and send a text to inactive windows too - with the same names ofc.

Edited by m4tius
Posted (edited)

Sure, that was just for example purposes.

Same concept though. you will have to use WinGetText to retrieve some text from the window and then use WinGetHandle (with the text you just obtained). once you have the handle of the window you can do "all of the above".:idea:

Try This:

open two notepads

write in one: this one

and in the other: that one

minimize them and then run this:

; Change into the WinTitleMatchMode that supports classnames and handles
AutoItSetOption("WinTitleMatchMode", 4)

; Get the handle of a notepad window that contains "this one"
$handle = WinGetHandle("classname=Notepad", "this one")
$handle2 = WinGetHandle("classname=Notepad", "that one")
If @error Then
    MsgBox(4096, "Error", "Could not find the correct window")
Else
    ; Send some text directly to this window's edit control
    ControlSend($handle, "", "Edit1", " is this one")
    ControlSend($handle2, "", "Edit1", " is the other one")
EndIf
Edited by billo
Posted (edited)

OK, this is it, but it probably wont works with 2 game windows. The best idea would be to check PIDs of these windows, but how to do that?

Edited by m4tius

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
  • Recently Browsing   0 members

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