Sign in to follow this  
Followers 0
Betrayal

ControlSend 2 Windows with the same name

8 posts in this topic

Hi,

I'm relatively new to AutoIT, and my problem is that I don't know how to send the letter "a" to two Notepads in the background.

Global $WinTitle ="Untitled - Notepad"

While 1

If WinExists($WinTitle)

  Then

    ControlSend($WinTitle, "", "", "a", 1)

  Else

    Exit

EndIf

WEnd

This, I believe, only works on one (the most recent one?). I want it to work on both.

What I'm planning to do later is close and save them, one of them as the current month, the other as the current day. But that's a different problem from the one I have right now, calling each instance individually.

Thanks in advance.

Share this post


Link to post
Share on other sites



Betrayal,

Welcome to the AutoIt forum. :)

Use WinList to get an array of the existing Notepad GUIs - then loop through the array using the returned handles, rather than the title, in the ControlSend call. :)

Better still, use [CLASS:Edit; INSTANCE:1] as the controlID parameter. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Betrayal,

Welcome to the AutoIt forum. :)

Use WinList to get an array of the existing Notepad GUIs - then loop through the array using the returned handles, rather than the title, in the ControlSend call. :)

Better still, use [CLASS:Edit; INSTANCE:1] as the controlID parameter. ;)

M23

Oh, that would solve both my problems. I'll try it out in a few minutes.

Share this post


Link to post
Share on other sites

Betrayal,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unneccessarily. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

My apologies.

So the basis of this method consists of looping through all instances with the same name, correct?

I also don't know where I can find information on Control ID; I don't know what that is, but I do know that it is a parameter.

Thanks,

Betrayal.

Share this post


Link to post
Share on other sites

Betrayal,

No problem - now you know. :)

 

So the basis of this method consists of looping through all instances with the same name

Exactly. :thumbsup:

 

where I can find information on Control ID

Look in the Help file (which should become a reflex action) under <Using AutoIt - Controls>. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Not exactly sure how this works. It writes 'a' twice to one of the documents. I know that $list[0][0] returns 2.

$list = WinList("Untitled - Notepad")
For $i = 1 To $list[0][0]
   If WinExists($list[$i][0]) Then
      ControlSend($list[$i][0], "", "[CLASS:Edit; INSTANCE:1]", "a", 1)
   Else
      Exit
   EndIf
Next

Share this post


Link to post
Share on other sites

$list = WinList("[CLASS:Notepad]")
For $i = 1 To $list[0][0]
   $controlHandle = ControlGetHandle($list[$i][1],"","[CLASS:Edit]")
   ControlSend("","",$controlHandle,"a")
Next

There you go :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0