Sign in to follow this  
Followers 0
BruceCopperField

Coordinating Multiple Windows

8 posts in this topic

I have mulitple windows each running a separate copy of my client software. I want my clients to perform some tasks in a coordinated manner which means I need to WinActivate() each at the appropriate time and send it the appropriate keystroke/mouseclick base on its current state. Currently, I am using one single script and manually perform multi-tasking to determine which of my window to activate and what state it is in and what keystroke it should get. However, this quickly becomes a complicated task as I need to keep track of the states of each of my client and determine exactly when to activate which one. Just like I am doing the task of an multi-tasking OS. Also, I need to hardcode the number of client in my script.

My idea is that is it possible to run, say, multiple copies of my script and simply utilise the multi-tasking capability of Windows so that I can write my script as if it is for a single client and create multi copies of it for each of my currently running clients.

A problem with my idea is that I need some interprocess communication facility and some way to mark the critical region of my script because at least each client need to know exactly when to activate its own window and issue Send() or otherwise the keystroke for one client may end up in another client. Could anyone provide me some hint as to how to achieve this. Thanks a lot

Share this post


Link to post
Share on other sites



I have mulitple windows each running a separate copy of my client software. I want my clients to perform some tasks in a coordinated manner which means I need to WinActivate() each at the appropriate time and send it the appropriate keystroke/mouseclick base on its current state. Currently, I am using one single script and manually perform multi-tasking to determine which of my window to activate and what state it is in and what keystroke it should get. However, this quickly becomes a complicated task as I need to keep track of the states of each of my client and determine exactly when to activate which one. Just like I am doing the task of an multi-tasking OS. Also, I need to hardcode the number of client in my script.

My idea is that is it possible to run, say, multiple copies of my script and simply utilise the multi-tasking capability of Windows so that I can write my script as if it is for a single client and create multi copies of it for each of my currently running clients.

A problem with my idea is that I need some interprocess communication facility and some way to mark the critical region of my script because at least each client need to know exactly when to activate its own window and issue Send() or otherwise the keystroke for one client may end up in another client. Could anyone provide me some hint as to how to achieve this. Thanks a lot

Post some example code so we can take a look.

Share this post


Link to post
Share on other sites

Thx,

Okay, this is my current approach (just pseudo code to ease reading):

Dim $MyClientHdl[5] ; I need to hard code the # my running client here

Dim $MyClientState[5];

..

; get the handles of the windows my client software and put it in $MyClientHdl[]

While true ; each loop will check each of the client once and issue some keystrokes to it

PerformTaskforClient($MyClientHdl[0])

PerformTaskforClient($MyClientHdl[1])

PerformTaskforClient($MyClientHdl[2])

PerformTaskforClient($MyClientHdl[3])

PerformTaskforClient($MyClientHdl[4])

Sleep(100)

WEnd

Func PerformTaskForClient($hdl)

; ... some logic to determine the what state each of my client is in

$taskrequired =...

If $taskrequired Then

WinActivate($hdl)

WinWaitActive($hdl)

Send(..)

Sleep(...) ;<--- each of my client needs some time to finish the task and I must wait before attempt to send a second

; issue commands to my client window.

EndIf

EndFunc

In this approach. firstly I need to hardcode the number of my running windows and, secondly, after I do a Send(...), I need to do a Sleep(.) to make sure my client can accept further keystroke. This 2 issues troubles me. For the second issue, I am looking for a simple way to switch to another window to do some useful job while sleeping and making sure that the proper order of the tasks are maintain. That means I don't want to send a second keystroke before my client can accept it.

Share this post


Link to post
Share on other sites

What I am looking for is a solution like this.

Each of my script works for only ONE of the window running my client software and I just run multiple copies of my script (asummes I have a way to make sure each running copy of my script know the handle to the window that it is supporting).

$myClientHdl=..

; assumes I know the handle to the target window of my script

WinActivate($myClientHdl)

WinWaitActive($myClientHdl)

;

; Somehow I need to prevent another copies of my script issuing its own WinActivate() when my script reach here but before reaching Send()

;

;

Send(..) ; issue a keystroke to one window only

Sleep(..) ; wait until the window accepting the keystroke finish processing and can proceed

Send (..) ; send further keystrokes

So far, I figure out at least I have to prevent another copy of my script to issue WinActivate() after my first copy issued its WinActivate() but before issuing Send(). Just wondering is there anyone with similar experience.

Share this post


Link to post
Share on other sites

Actually you don't have to hardcode anything,look in the documentation for 'Redim',and use a For loop.

Share this post


Link to post
Share on other sites

How is it possible to prevent another copy of my script issuing WinActivate() right after my first copy issued a WinActivate() but before issuing Send()?

Share this post


Link to post
Share on other sites

If instead of using a While loop you use a For loop you will not have a worry!

I'll try and show you... just the part which I'm changing

This is what you had:

While true; each loop will check each of the client once and issue some keystrokes to it
PerformTaskforClient($MyClientHdl[0])
PerformTaskforClient($MyClientHdl[1])
PerformTaskforClient($MyClientHdl[2])
PerformTaskforClient($MyClientHdl[3])
PerformTaskforClient($MyClientHdl[4])
Sleep(100)
WEnd

To prevent the problem you speak of, use a for loop:

While true; Now all this loop does is make your loop repeat over and over again
For $i=0 to 4; As it seems there are five members in your array (0 to 4)
PerformTaskforClient($MyClientHdl[$i]); This is the variable which changes in your for loop, meaning all our windows will be checked!
Next
Sleep(100); I'm not sure why you put in a sleep of 100 milliseconds but I'll leave it in here as it was in your original script
WEnd

That should work hopefully!! :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Woops it double posted sorry!

But I'm not sure what you mean by...

How is it possible to prevent another copy of my script issuing WinActivate() right after my first copy issued a WinActivate() but before issuing Send()?

Why do you need all the winactivates done before you use the send

Edited by hisbigego

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