Jump to content
DuByD

Client Window and activating changes?

Recommended Posts

Had several old scripts that ran under I believe 3.35. I have just setup/reloaded and older computer and downloaded the latest version and my scripts are no longer activating and setting the area for the windows it seems... I have written a simple script to take two notepad windows and move the mouse around the inner window area starting at 10% -90%, X and Y, to move the mouse around a TBox that I have setup... Can anyone help me as to figure out what has changed?

 

program MultipleClientTest;
 var  
   Wnds: THwndArray;
   ClientVM1,ClientVM2 : TSCARWindowClient;
   VM1Width, VM1Height : Integer;
   VM2Width, VM2Height : Integer;
   VM1TB,VM2TB : TBox;
   TBoxX1,TBoxX2,TBoxY1,TBoxY2 : Single;  
const
   VM1Title = 'test1 .*/i'; 
   VM2Title = 'test2 .*/i';
   Debug = True;
   DebugMsgWait = 500;          
procedure DebugInfo(msg : String);
begin
 WriteLn(msg);
 Wait(DebugMsgWait);
end;
procedure SetupClientVM1;
begin
 If Debug Then DebugInfo('Setting Up Client VM1.');  
 Wnds := FindWindowsPreg(GetDesktopWindow,VM1Title,'', False);
 WriteLn(Wnds[0]);      
 ClientVM1 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM1); 
 ClientVM1.Activate;    
 ClientVM1.ClientArea := True;
 VM1Width := ClientVM1.ImageArea.X2 + 1;
 VM1Height := ClientVM1.ImageArea.Y2 + 1;    
end;
procedure SetupClientVM2;
begin
 If Debug Then DebugInfo('Setting Up Client VM2.');  
 Wnds := FindWindowsPreg(GetDesktopWindow,VM2Title,'', False);      
 ClientVM2 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM2); 
 ClientVM2.Activate;    
 ClientVM2.ClientArea := True;
 VM2Width := ClientVM2.ImageArea.X2 + 1;
 VM2Height := ClientVM2.ImageArea.Y2 + 1;    
end;
procedure SetupRatios;
begin
 If Debug Then DebugInfo('Setting Up Ratios.');
   //Screen Percentages    
   TBoxX1 := 0.1;
   TBoxX2 := 0.9;
   TBoxY1 := 0.1;
   TBoxY2 := 0.9;
end;
function CreateTBox(X,Y : Integer; RX1,RY1,RX2,RY2 : Single) : TBox;
var tb : TBox;
   X1,X2,Y1,Y2 : Integer;
begin
 If Debug Then DebugInfo('Setting Up Box.');
   X1 := Floor(X * RX1);
   X2 := Floor(X * RX2);
   Y1 := Floor(Y * RY1);
   Y2 := Floor(Y * RY2);
   tb := Box(X1,Y1,X2,Y2);
   Result := tb;
end;
procedure SetupBoxesVM1;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM1.'); 
 VM1TB := CreateTBox(VM1Width,VM1Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure SetupBoxesVM2;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM2.'); 
 VM2TB := CreateTBox(VM2Width,VM2Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure MoveMouseAroundTBox(Client : TSCARWindowClient; tb : TBox);
begin
   SetClient(Client);
   Client.Activate;
   Client.ClientArea := True; 
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
end;

begin
 SetupClientVM1;
 SetupClientVM2;
 SetupRatios;
 SetupBoxesVM1;
 SetupBoxesVM2;
 MoveMouseAroundTBox(ClientVM1,VM1TB);
 MoveMouseAroundTBox(ClientVM2,VM2TB);
end.

 

- - - Updated - - -

 

Should have added that I created two notepad documents and saved them as test1 and test2. The tBox is created using ratios because the screens that I am dealing with can be changed in size or scaled. I am using virtual box VMs. This way I can define search areas via the tboxs that are set to each VMs scaling... So this should grab the size of the area of the notepad documents and move the mouse around then the same regardless of the size of the windows.

MultipleClientTest.txt

Link to comment
Share on other sites

I found my own problem... LOL... VM1Title = 'test1 .*/i'; needed to be VM1Title = '/test1 .*/i';

Now with this new program, I am not finding the correct client... Is there any way to get the title of the window from the handle?

 

- - - Updated - - -

 

Finding my actual VMs now... Running MEmu instead of VBox and was a little tougher to pick the title correctly than before...

Changed

Wnds := FindWindowsPreg(GetDesktopWindow,VM1Title,'', False);
to
Wnds := FindWindows(VM1Title);
for both and it is finding them now... with the other way without the "/" it was finding something just not the correct window.

 

Now a very odd thing is happening that I cannot wrap my head around... When I run the test script, the mouse doesn't move... But after clicking run, when it gets to the mouse movement part, if I click on a blank spot on my desktop, the mouse will move to the correct location... I have to click a blank area between each call to MoveMouseAroundTBox. Is this because I have to have the parent window, the desktop selected before setting and activating the clients again? Sorry it has been a couple of years since I did this... lol Used a debug message to time when to click on the desktop...

 

program MultipleClientTest;
 var  
   Wnds: THwndArray;
   ClientVM1,ClientVM2 : TSCARWindowClient;
   VM1Width, VM1Height : Integer;
   VM2Width, VM2Height : Integer;
   VM1TB,VM2TB : TBox;
   TBoxX1,TBoxX2,TBoxY1,TBoxY2 : Single;  
const
   VM1Title = 'MEmu 2.1.1 - MEmu_1'; 
   VM2Title = 'MEmu 2.1.1 - MEmu_2';
   Debug = True;
   DebugMsgWait = 500;          
procedure DebugInfo(msg : String);
begin
 WriteLn(msg);
 Wait(DebugMsgWait);
end;
procedure SetupClientVM1;
begin
 If Debug Then DebugInfo('Setting Up Client VM1.');  
 //Wnds := FindWindowsPreg(GetDesktopWindow,VM1Title,'', False);
 Wnds := FindWindows(VM1Title);
 WriteLn(Wnds[0]);      
 ClientVM1 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM1); 
 ClientVM1.Activate;    
 ClientVM1.ClientArea := True;
 VM1Width := ClientVM1.ImageArea.X2 + 1;
 VM1Height := ClientVM1.ImageArea.Y2 + 1;    
end;
procedure SetupClientVM2;
begin
 If Debug Then DebugInfo('Setting Up Client VM2.');  
 //Wnds := FindWindowsPreg(GetDesktopWindow,VM2Title,'', False);      
 Wnds := FindWindows(VM2Title);      
 WriteLn(Wnds[0]);      
 ClientVM2 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM2); 
 ClientVM2.Activate;    
 ClientVM2.ClientArea := True;
 VM2Width := ClientVM2.ImageArea.X2 + 1;
 VM2Height := ClientVM2.ImageArea.Y2 + 1;    
end;
procedure SetupRatios;
begin
 If Debug Then DebugInfo('Setting Up Ratios.');
   //Screen Percentages    
   TBoxX1 := 0.1;
   TBoxX2 := 0.9;
   TBoxY1 := 0.1;
   TBoxY2 := 0.9;
end;
function CreateTBox(X,Y : Integer; RX1,RY1,RX2,RY2 : Single) : TBox;
var tb : TBox;
   X1,X2,Y1,Y2 : Integer;
begin
 If Debug Then DebugInfo('Setting Up Box.');
   X1 := Floor(X * RX1);
   X2 := Floor(X * RX2);
   Y1 := Floor(Y * RY1);
   Y2 := Floor(Y * RY2);
   tb := Box(X1,Y1,X2,Y2);
   WriteLn(BoxToStr(tb));
   Result := tb;
end;
procedure SetupBoxesVM1;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM1.'); 
 VM1TB := CreateTBox(VM1Width,VM1Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure SetupBoxesVM2;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM2.'); 
 VM2TB := CreateTBox(VM2Width,VM2Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure MoveMouseAroundTBox(Client : TSCARWindowClient; tb : TBox);
begin
   If Debug Then DebugInfo('Moving Mouse!'); 
   SetClient(Client);
   Client.Activate;
   Client.ClientArea := True; 
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
end;

begin
 SetupClientVM1;
 SetupClientVM2;
 SetupRatios;
 SetupBoxesVM1;
 SetupBoxesVM2;
 MoveMouseAroundTBox(ClientVM1,VM1TB);
 MoveMouseAroundTBox(ClientVM2,VM2TB);
end.

 

- - - Updated - - -

 

Also, after the clients are setup, if I put IE or something over the windows, the mouse moves in the places on the IE window over the two targeted windows. The placeholders in the taskbar start flashing orange when the MoveMouseAroundTBox is called like they are being activated, but they are not brought to the front of the screen, but the mouse placement is correct...

 

- - - Updated - - -

 

program MultipleClientTest;
 var  
   Wnds: THwndArray;
   ClientVM1,ClientVM2 : TSCARWindowClient;
   VM1Width, VM1Height : Integer;
   VM2Width, VM2Height : Integer;
   VM1TB,VM2TB : TBox;
   TBoxX1,TBoxX2,TBoxY1,TBoxY2 : Single;  
const
   VM1Title = 'MEmu 2.1.1 - MEmu_1'; 
   VM2Title = 'MEmu 2.1.1 - MEmu_2';
   //VM1Title = 'test1 - Notepad'; 
   //VM2Title = 'test2 - Notepad';
   Debug = True;
   DebugMsgWait = 500;          
procedure DebugInfo(msg : String);
begin
 WriteLn(msg);
 Wait(DebugMsgWait);
end;
procedure SetupClientVM1;
begin
 If Debug Then DebugInfo('Setting Up Client VM1.');  
 //Wnds := FindWindowsPreg(GetDesktopWindow,'MEmu 2.1.1 - MEmu_1 .*','', False);
 //Wnds := FindWindowsPreg(GetDesktopWindow,VM1Title,'', False);
 Wnds := FindWindows(VM1Title);
 WriteLn(Wnds[0]);      
 ClientVM1 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM1); 
 ClientVM1.Activate;    
 ClientVM1.ClientArea := True;
 VM1Width := ClientVM1.ImageArea.X2 + 1;
 VM1Height := ClientVM1.ImageArea.Y2 + 1;    
end;
procedure SetupClientVM2;
begin
 If Debug Then DebugInfo('Setting Up Client VM2.');  
 //Wnds := FindWindowsPreg(GetDesktopWindow,'MEmu 2.1.1 - MEmu_2 .*','', False);      
 //Wnds := FindWindowsPreg(GetDesktopWindow,VM2Title,'', False);      
 Wnds := FindWindows(VM2Title);      
 WriteLn(Wnds[0]);      
 ClientVM2 := TSCARWindowClient.Create(Wnds[0]);
 SetClient(ClientVM2); 
 ClientVM2.Activate;    
 ClientVM2.ClientArea := True;
 VM2Width := ClientVM2.ImageArea.X2 + 1;
 VM2Height := ClientVM2.ImageArea.Y2 + 1;    
end;
procedure SetupRatios;
begin
 If Debug Then DebugInfo('Setting Up Ratios.');
   //Screen Percentages    
   TBoxX1 := 0.1;
   TBoxX2 := 0.9;
   TBoxY1 := 0.1;
   TBoxY2 := 0.9;
end;
function CreateTBox(X,Y : Integer; RX1,RY1,RX2,RY2 : Single) : TBox;
var tb : TBox;
   X1,X2,Y1,Y2 : Integer;
begin
 If Debug Then DebugInfo('Setting Up Box.');
   X1 := Floor(X * RX1);
   X2 := Floor(X * RX2);
   Y1 := Floor(Y * RY1);
   Y2 := Floor(Y * RY2);
   tb := Box(X1,Y1,X2,Y2);
   WriteLn(BoxToStr(tb));
   Result := tb;
end;
procedure SetupBoxesVM1;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM1.'); 
 VM1TB := CreateTBox(VM1Width,VM1Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure SetupBoxesVM2;
begin
 If Debug Then DebugInfo('Setting Up Boxes VM2.'); 
 VM2TB := CreateTBox(VM2Width,VM2Height,TBoxX1,TBoxY1,TBoxX2,TBoxY2);
end;
procedure MoveMouseAroundTBox(Client : TSCARWindowClient; tb : TBox);
begin
   If Debug Then DebugInfo('Moving Mouse!'); 
   SetClient(Client);
   Client.Activate;
   Client.ClientArea := True; 
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y1);
   wait(1000)
   MoveMouse(tb.X2,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y2);
   wait(1000)
   MoveMouse(tb.X1,tb.Y1);
   wait(1000)
end;

begin
 SetupClientVM1;
 SetupClientVM2;
 SetupRatios;
 SetupBoxesVM1;
 SetupBoxesVM2;
 MoveMouseAroundTBox(ClientVM1,VM1TB);
 MoveMouseAroundTBox(ClientVM2,VM2TB);
end.

 

- - - Updated - - -

 

The above works with notepad but not MEmu VMs... :(

Edited by DuByD
spelling
Link to comment
Share on other sites

Yeah I tested it... (frownyface) I am actually able to get focus of the window now by using FindWondow but tried this as well... The problem is that after you set and activate the client now, the mouse doesn't move unless you click on something outside of scar and you have to do it on each client as it switches... If you don't touch the mouse, it just sits there... It works fine with regular windows, I was just trying a new emulator called MEmu because it allows multiple instances... Where I had used virtualbox in the past. Virtualbox is great, but need a newer android image to run the game I am working on. The great thing about the older versions of android in virtualbox is that it didn't capture your mouse which makes scripting easy when switching between many VMs. The newer versions capture the mouse and you have to escape the mouse before switching VMs and it makes getting in and out of them troublesome... MEmu doesn't capture the mouse as others do. Very interesting emulator but I don't think the issue is with the script but maybe how MEmu emulator controls its windows.... So might just be out of luck and have to keep trying with VBox some more to see if I can get around the screen capture like you could with the ice cream version of android...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...