Jump to content

Run a script in multiple windows


Recommended Posts

Hi everyone,

I am super new with autoit. Basically, i just learned it today. And I have done some experiments.

Right now, i am looking for the solution to work with multiple windows by using one script only.

For example, 

My software name is "MSO"

Functions: Execute F2 and ALT+2

 

and my script is

HotKeySet("{ESC}", "MyExit")
 
Func MyExit()
   Exit
EndFunc
 
 
While 1
 ControlSend ( "MSO", "", "", "{f2}")
 Sleep(800)
 ControlSend ( "MSO, "", "", "!2")
 
sleep (500)
WEnd
 
My current problem is, it works in one window only. and that window must be presented on the screen (must not be hidden, but can be inactive). So how to solve the problem??
 
I would appreciate if all of you can help me to solve the problem.
 
Rgds,
yo
 
Link to comment
Share on other sites

  • Moderators

Whysilvers,

Use the handles of the 2 windows to differentiate them - then you can use the same script to address them both. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Whysilvers,

Use the handles of the 2 windows to differentiate them - then you can use the same script to address them both. :)

M23

Thanks for reply.

How to get handles? As i used AutoItv3 window info to search the info, in the "handle" column doesn't have any detail. and the all the windows that i opened have same name, MSO. would you mind guide me a little bit? ;)

Thanks

Link to comment
Share on other sites

  • Moderators

Whysilvers,

Use WinList to get the handles of the 2 windows named "MSO" - then you can use these handles in place of the "title" parameter when using other functions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Whysilvers,

Use the handles of the 2 windows to differentiate them - then you can use the same script to address them both. :)

M23

Dear Melba,

Thanks for your help. You really guided me a lot. and now the things go further a bit.

Right now I managed to get the window handle. and need to do some improvement.

Basically, i can get handle into the script. but how to ask the script run all the existing "MSO" windows?

Here is my script

HotKeySet("{ESC}", "MyExit")
 
 
Local $aWinList = WinList ("[REGEXPTITLE:(?i)(.*MSO)]")
 
 
Func MyExit()
   Exit
EndFunc
 
 
While 1
 
 If ControlSend ( "$aWinList[1[1", "", "", "{f2}") Then
 Sleep(100)
   EndIf
 
 If ControlSend ( "$aWinList[1[1", "", "", "!+2") Then
sleep (300)
   EndIf
 
 
 
WEnd
 
 
As you can see, now i am only able to run 1st window only. 
 
One more thing, i discovered that when i run the script, it affect my normal function as well. the F2 function keep disturbing my active windows. 
 
Hope you can guide me to improve my script.
 
 
Thanks 
Link to comment
Share on other sites

Are you changing the language when you run the installer or after the application has been installed on the PC? If it is after the software has been installed have you looked to see where the software keeps it settings? Is it an INI file? Registry? If it is kept in either one of those places then it is easy to make the change you need.

For modifying the INI file, look at INIRead, INIWrite in the AutoIt help file.

For the registry look at RegRead and RegWrite in the AutoIt help file.

Link to comment
Share on other sites

Basically, i solved the Handles issue. 

However, even I have the Handles, why the controlsend fuction doesn't work?

I need to exit the script, manually key in handle into Controlsend "xxxxxx". Then it will work. 

How to make the script automatically get the handle, put into controlsend's title, and work immediately?

thanks

Link to comment
Share on other sites

  • Moderators

Whysilvers,

Post the code you have tried - perhaps we can see why it is not working. :)

M23

P.S. When you post code please use Code tags - see here how to do it. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

 

Here is my code which i need to key in handle later on
 
 
HotKeySet("{ESC}", "MyExit")
HotKeySet ("!a", "getWinList")
HotkeySet ("!c", "Start")


Local $aWinList
Global $nowin
Func MyExit()
   Exit
EndFunc


Func getWinList()
$aWinList = Winlist ("[REGEXPTITLE:MSO]")
$nowin = $aWinList[1][1]


   MsgBox(0, "Handle", "The handle has been set to " & $nowin)
EndFunc


Func Start()
   MsgBox(64,"INFO", "start function")
   While 1


   ControlSend ( "$nowin", "", "q")
 Sleep(700)
 ControlSend ( "$nowin", "", "", "\")


EndIf
sleep (200)
WEnd
EndFunc


While 1
   sleep(150)
WEnd
 
and also, how to let this script to send "controlsend" to 2 windows? as i 've tried
 
 
ControlSend ( "0x00002222 AND 0x0003333", "", "q")
 Sleep(700)
 ControlSend ( "0x00002222 AND 0x0003333", "", "", "\")
 
also cannot work.
 
and i tried to separate windows 1 and windows 2 into 2 functions, by setting 2 Hotkeyset. when i activate both, the latest one will work, and the previous one won't work.
 
thanks in advance
 

 

Link to comment
Share on other sites

  • Moderators

WhySilvers,

You need to learn about arrays! I suggest starting with the Arrays tutorial in the Wiki. ;)

Open 2 Notepad windows and run this - it shows how you deal with multiple windows

#include <Array.au3> ; Just for display of the window array

HotKeySet("{ESC}", "MyExit")
HotKeySet("!a", "getWinList")
HotKeySet("!c", "Start")

Global $aWinList

While 1
    Sleep(10)
WEnd

Func MyExit()
    Exit
EndFunc   ;==>MyExit

Func getWinList()
    ; Match windows with MSO as a substring in the title
    $iOldMode = Opt("WinTitleMatchMode", 2)
    ; Get an array of the matching windows
    $aWinList = WinList("Notepad")
    ; Reset the mode
    Opt("WinTitleMatchMode", $iOldMode)
    ; Just to show you what we get
    _ArrayDisplay($aWinList, "", Default, 8)

EndFunc   ;==>getWinList

Func Start()
    MsgBox(64, "INFO", "start function")
    ; Loop through the array of matching windows
    For $i = 1 To $aWinList[0][0]
        ; Extract the handle from the array
        $hWnd = HWnd($aWinList[$i][1])
        ; Now run a minimize/restore cycle on each Notepad window to show that it works for each
        WinSetState($hWnd, "", @SW_MINIMIZE)
        Sleep(1000)
        WinSetState($hWnd, "", @SW_RESTORE)
        Sleep(1000)
    Next
EndFunc   ;==>Start
Please ask if you have any questions. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

WhySilvers,

You need to learn about arrays! I suggest starting with the Arrays tutorial in the Wiki. ;)

Open 2 Notepad windows and run this - it shows how you deal with multiple windows

#include <Array.au3> ; Just for display of the window array

HotKeySet("{ESC}", "MyExit")
HotKeySet("!a", "getWinList")
HotKeySet("!c", "Start")

Global $aWinList

While 1
    Sleep(10)
WEnd

Func MyExit()
    Exit
EndFunc   ;==>MyExit

Func getWinList()
    ; Match windows with MSO as a substring in the title
    $iOldMode = Opt("WinTitleMatchMode", 2)
    ; Get an array of the matching windows
    $aWinList = WinList("Notepad")
    ; Reset the mode
    Opt("WinTitleMatchMode", $iOldMode)
    ; Just to show you what we get
    _ArrayDisplay($aWinList, "", Default, 8)

EndFunc   ;==>getWinList

Func Start()
    MsgBox(64, "INFO", "start function")
    ; Loop through the array of matching windows
    For $i = 1 To $aWinList[0][0]
        ; Extract the handle from the array
        $hWnd = HWnd($aWinList[$i][1])
        ; Now run a minimize/restore cycle on each Notepad window to show that it works for each
        WinSetState($hWnd, "", @SW_MINIMIZE)
        Sleep(1000)
        WinSetState($hWnd, "", @SW_RESTORE)
        Sleep(1000)
    Next
EndFunc   ;==>Start
Please ask if you have any questions. :)

M23

 

Wow!!! IT worKs flawlessly. thanks a lot for your help. You really solve my frustration.

Million thanks again!

Link to comment
Share on other sites

  • Moderators

Whysilvers,

Glad I could help. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I want to do some improvement on my script. 

Basically, i want everything run normally. and i want after certain period, the script will press F5 to refresh. 

But when i tried to use sleep (xxx), it paused the whole script and the script won't run for xxx mil second. 

is there any better way i can use to replace sleep () ?

 

thanks

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