Jump to content

Controlsend to multiple windows


Das Ami
 Share

Recommended Posts

I need to send a string to multiple undefined windows called unbenannt.

But it sends the strings to the same window every single time and I can't find the error. =/

Opt("TrayAutoPause",0)

HotKeySet("{NUMPAD2}","two")
HotKeySet("{NUMPAD3}","three")
HotKeySet("{NUMPAD4}","four")
HotKeySet("{NUMPAD5}","five")
HotKeySet("{NUMPAD6}","six")
HotKeySet("{NUMPAD7}","seven")
HotKeySet("{NUMPAD8}","eight")
HotKeySet("{NUMPAD9}","nine")
HotKeySet("{NUMPAD0}","zero")
HotKeySet("{NUMPADADD}","tab")

$var = WinList("Unbenannt")
$count = 1

For $i=1 to $var[0][0]
WinSetTitle ("Unbenannt", "", $count)
$count=$count+1
Next

Func two()
For $i=1 to $count
ControlSend($i, "", "", "2",1)
Next
EndFunc

Func three()
For $i=1 to $count
ControlSend($i, "", "", "3",1)
$i=$i+1
Next
EndFunc

Func four()
For $i=1 to $count
ControlSend($i, "", "", "4",1)
Next
EndFunc

Func five()
For $i=1 to $count
ControlSend($i, "", "", "5",1)
Next
EndFunc

Func six()
For $i=1 to $count
ControlSend($i, "", "", "6",1)
Next
EndFunc

Func seven()
For $i=1 to $count
ControlSend($i, "", "", "7",1)
Next
EndFunc

Func eight()
For $i=1 to $count
ControlSend($i, "", "", "8",1)
Next
EndFunc

Func nine()
For $i=1 to $count
ControlSend($i, "", "", "9",1)
Next
EndFunc

Func zero()
For $i=1 to $count
ControlSend($i, "", "", "0",1)
Next
EndFunc

Func tab()
For $i=1 to $count
ControlSend($i, "", "", "{TAB}",1)
Next
EndFunc

While 1
    Sleep (100)
WEnd
Edited by Das Ami
Link to comment
Share on other sites

Not sure if this is right, but it's probably a lot closer than what you have:

Opt("TrayAutoPause",0)

; Put the ClassNameNN of the control you want to send to here
Global Const $ControlToSendTo = "[CLASSNN:Edit1]"

HotKeySet("{NUMPAD2}","two")
HotKeySet("{NUMPAD3}","three")
HotKeySet("{NUMPAD4}","four")
HotKeySet("{NUMPAD5}","five")
HotKeySet("{NUMPAD6}","six")
HotKeySet("{NUMPAD7}","seven")
HotKeySet("{NUMPAD8}","eight")
HotKeySet("{NUMPAD9}","nine")
HotKeySet("{NUMPAD0}","zero")
HotKeySet("{NUMPADADD}","tab")

Global $var = WinList("Unbenannt")

; don't know what all this is for, but my guess is you don't need it.
For $i=1 to $var[0][0]
   WinSetTitle ($var[1][$i], "", $i)
Next

Func two()
   TheWork("2")
EndFunc

Func three()
   TheWork("3")
EndFunc

Func four()
   TheWork("4")
EndFunc

Func five()
   TheWork("5")
EndFunc

Func six()
   TheWork("6")
EndFunc

Func seven()
   TheWork("7")
EndFunc

Func eight()
   TheWork("8")
EndFunc

Func nine()
   TheWork("9")
EndFunc

Func zero()
   TheWork("0")
EndFunc

Func tab()
   TheWork("{TAB}")
EndFunc

Func TheWork($text)
   Local $i
   For $i=1 to $var[0][0]
      ControlSend($var[1][$i], "", $ControlToSendTo, $text,  1)
   Next
EndFunc


While 1
    Sleep (100)
Wend

HTH

Edited by Klaatu
My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!
Link to comment
Share on other sites

Merry Christmas, and don't say I didn't get you anything:

Opt("TrayAutoPause", 0)

Global $avHotKeys[10] = ["{NUMPAD0}", "{NUMPAD2}", "{NUMPAD3}", "{NUMPAD4}", "{NUMPAD5}", "{NUMPAD6}", _
        "{NUMPAD7}", "{NUMPAD8}", "{NUMPAD9}", "{NUMPADADD}"]
For $i = 0 To UBound($avHotKeys) - 1
    HotKeySet($avHotKeys[$i], "_HotKeyHit")
Next

$avWinList = WinList("Unbenannt")
For $i = 1 To $avWinList[0][0]
    $avWinList[$i][0] = $i
    WinSetTitle($avWinList[$i][1], "", $i)
Next

While 1
    Sleep(100)
WEnd

Func _HotKeyHit()
    Local $sHotKey = @HotKeyPressed
    $sHotKey = StringMid($sHotKey, 8, 1)
    If $sHotKey = "A"  Then $sHotKey = "{TAB}"
    For $i = 1 To $avWinList[0][0]
        ControlSend($avWinList[$i][1], "", "", $sHotKey)
    Next
EndFunc   ;==>_HotKeyHit

:)

Edit: Tweaked bad StringMid() parameter.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Merry Christmas, and don't say I didn't get you anything:

Opt("TrayAutoPause", 0)

Global $avHotKeys[10] = ["{NUMPAD0}", "{NUMPAD2}", "{NUMPAD3}", "{NUMPAD4}", "{NUMPAD5}", "{NUMPAD6}", _
        "{NUMPAD7}", "{NUMPAD8}", "{NUMPAD9}", "{NUMPADADD}"]
For $i = 0 To UBound($avHotKeys) - 1
    HotKeySet($avHotKeys[$i], "_HotKeyHit")
Next

$avWinList = WinList("Unbenannt")
For $i = 1 To $avWinList[0][0]
    $avWinList[$i][0] = $i
    WinSetTitle($avWinList[$i][1], "", $i)
Next

While 1
    Sleep(100)
WEnd

Func _HotKeyHit()
    Local $sHotKey = @HotKeyPressed
    $sHotKey = StringMid($sHotKey, 8, 1)
    If $sHotKey = "A"  Then $sHotKey = "{TAB}"
    For $i = 1 To $avWinList[0][0]
        ControlSend($avWinList[$i][1], "", "", $sHotKey)
    Next
EndFunc   ;==>_HotKeyHit

:)

Edit: Tweaked bad StringMid() parameter.

You have a nice coding structure and thanks alot - but it still sends the strings to one and the same window.

By the way, Unbenannt is just the german name of notepad (Untitled).

Link to comment
Share on other sites

Well, unless you can be more specific about what doesn't work, I can't help you.

Did you change this to match the name of the control you're trying to send to?

Global Const $ControlToSendTo = "[CLASSNN:Edit1]"
Sorry I think you got me wrong, I need to send a string to all open windows with the title 'Unbenannt' (that's notepad) when I press a hotkey.

Psalty's on the right track but I'm getting the same results as with my first script.

It seems to loop through the windows but it sends all strings to one single window.

Link to comment
Share on other sites

Since it's just Notepad, I was able to test. Notepad doesn't like the empty Control ID, so I explicitly put "Edit1" in there:

Opt("TrayAutoPause", 0)

; Get me three notepads to play with
For $n = 1 To 3
    Run("Notepad.exe")
    Sleep(500) ; Give them time to open or WinList won't see them
Next

Global $avHotKeys[10] = ["{NUMPAD0}", "{NUMPAD2}", "{NUMPAD3}", "{NUMPAD4}", "{NUMPAD5}", "{NUMPAD6}", _
        "{NUMPAD7}", "{NUMPAD8}", "{NUMPAD9}", "{NUMPADADD}"]
For $i = 0 To UBound($avHotKeys) - 1
    HotKeySet($avHotKeys[$i], "_HotKeyHit")
Next

$avWinList = WinList("Untitled - Notepad")
For $i = 1 To $avWinList[0][0]
    $avWinList[$i][0] = $i
    WinSetTitle($avWinList[$i][1], "", $i)
    WinMove($avWinList[$i][1], "", $i * 75, $i * 175, 300, 150, 5)
Next

While 1
    Sleep(100)
WEnd

Func _HotKeyHit()
    Local $sHotKey = @HotKeyPressed
    $sHotKey = StringMid($sHotKey, 8, 1)
    If $sHotKey = "A"  Then $sHotKey = "{TAB}"
    For $i = 1 To $avWinList[0][0]
        ControlSend($avWinList[$i][1], "", "Edit1", $sHotKey)
    Next
EndFunc   ;==>_HotKeyHit

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Since it's just Notepad, I was able to test. Notepad doesn't like the empty Control ID, so I explicitly put "Edit1" in there:

Opt("TrayAutoPause", 0)

; Get me three notepads to play with
For $n = 1 To 3
    Run("Notepad.exe")
    Sleep(500) ; Give them time to open or WinList won't see them
Next

Global $avHotKeys[10] = ["{NUMPAD0}", "{NUMPAD2}", "{NUMPAD3}", "{NUMPAD4}", "{NUMPAD5}", "{NUMPAD6}", _
        "{NUMPAD7}", "{NUMPAD8}", "{NUMPAD9}", "{NUMPADADD}"]
For $i = 0 To UBound($avHotKeys) - 1
    HotKeySet($avHotKeys[$i], "_HotKeyHit")
Next

$avWinList = WinList("Untitled - Notepad")
For $i = 1 To $avWinList[0][0]
    $avWinList[$i][0] = $i
    WinSetTitle($avWinList[$i][1], "", $i)
    WinMove($avWinList[$i][1], "", $i * 75, $i * 175, 300, 150, 5)
Next

While 1
    Sleep(100)
WEnd

Func _HotKeyHit()
    Local $sHotKey = @HotKeyPressed
    $sHotKey = StringMid($sHotKey, 8, 1)
    If $sHotKey = "A"  Then $sHotKey = "{TAB}"
    For $i = 1 To $avWinList[0][0]
        ControlSend($avWinList[$i][1], "", "Edit1", $sHotKey)
    Next
EndFunc   ;==>_HotKeyHit
But it works perfectly now.

Thank you, that's a huge relief. :)

Link to comment
Share on other sites

Autoit complained about the last parameter in:

WinMove($avWinList[$i][1], "", $i * 75, $i * 175, 300, 150, 5)

But it works perfectly now.

Thank you, that's a huge relief. :)

Glad it works for you.

Are you running AutoIt 3.2.10.0?

That last parameter is SPEED; it controls how fast the window moves, and it's new. So if you are running an older version it might not be recognized.

^_^

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...