Jump to content
GambadiFerro

A simple script conversion to 3.35

Recommended Posts

I would like to convert this simple script to SCAR 3.35.

This script simply identify an image on the desktop and move the mouse on it.

There are some functions that have been deprecated and others that I don't know how to handle them (i.e. SetDesktopAsClient ).

Anybody could simply convert this script in the new version?

Thank you!!!!!!!!!

 

 

program New;
 var bmp,xx,yy: Integer;
begin

 ClearDebug;
 wait(5000);

 SetDesktopAsClient;

 bmp := BitmapFromString(12, 12, 'ceNpjYGAQEBBYuWZDdMcG0' +
   '6xp5vnzLAvmWhbMtiqYa1U40yJvlkHm5ImTpvz//9+pZIF2Yp9Jx' +
   'lSzrOnm2dPMcuZYZM0yzpihEt+jHt0HVJDSuVY9tts8c4J5zgzj2' +
   'AYltwR520AFOz8Fj/Stx68/e/3hxLUXypGtJhlTLLNnqAUUiBvYy' +
   'ho7SZm6CWlZ5te0/weDwinbtBJ7TTKn6MY2SOtbyZi7KZg7ypp78' +
   'Gtbl7X2QdS4lswzSuk2yZ2l4hgsbeIib+YsbeEubeYqZ+ooauCy6' +
   '+Cx5+/eWWZNMUzttcieIW/hJQ40xMxRysxD1txN1sxV0tRVQMOCR' +
   '93SOneGfsZki8zp8taecmbO8qYe0uYusmZuQEtlzV1lzNzljGxC6' +
   '5dop06wzJqh7JkgbWwrbeopY+4EVWPmJm3uLmNoOXXTSbWYHtP0K' +
   'WapXRLGdmBbnIEmyJq6ypq5yJo6yFgHfPr8XzOp0ySlDxjIRnFt4' +
   'sb2Msb2UiaOsqZOkibOEmZelqnd73/+33rknkxIIzCITLKnWqRP1' +
   'PRJV7ILkbcL0PLJsszoN8maCgD+RpxY');

     if (FindBitmapTolerance(bmp, xx, yy, 42)=true) then begin
      MoveMouse(xx,yy);
     end;

end.

Edited by GambadiFerro
Link to comment
Share on other sites

[scar]var

client: TSCARClient;

bmp: TSCARBitmap;

X, Y: Integer;

bx: TBox;

 

begin

ClearDebug;

bmp := TSCARBitmap.Create('');

bmp.LoadFromStr('deNrjYeBhAAIBAYGVazZEd2wwzZpmnj/PsmCuZcFsq4K5VoU' +

'zLfJmGWROnjhpyv///51KFmgn9plkTDXLmm6ePc0sZ45F1izjjBkq8T3q0X1ABSmda9Vju80' +

'zJ5jnzDCObVByS5C3DVSw81PwSN96/Pqz1x9OXHuhHNlqkjHFMnuGWkCBuIGtrLGTlKmbkJZ' +

'lfk37fzAonLJNK7HXJHOKbmyDtL6VjLmbgrmjrLkHv7Z1WWsfRI1ryTyjlG6T3FkqjsHSJi7' +

'yZs7SFu7SZq5ypo6iBi67Dh57/u6dZdYUw9Rei+wZ8hZe4kBDzBylzDxkzd1kzVwlTV0FNCx' +

'41C2tc2foZ0y2yJwub+0pZ+Ysb+ohbe4ia+YGtFTW3FXGzF3OyCa0fol26gTLrBnKngnSxrb' +

'Spp4y5k5QNWZu0ubuMoaWUzedVIvpMU2fYpbaJWFsB7bFGWiCrKmrrJmLrKmDjHXAp8//NZM' +

'6TVL6gIFsFNcmbmwvY2wvZeIoa+okaeIsYeZlmdr9/uf/rUfuyYQ0AoPIJHuqRfpETZ90Jbs' +

'QebsALZ8sy4x+k6ypACchnHA=');

client := SetClient(TSCARWindowClient.Create(GetDesktopWindow));

client.Activate;

bx := client.InputArea;

Wait(5000);

if FindBitmapTol(X, Y, bmp, bx.X1, bx.Y1, bx.X2, bx.Y2, 42) then

MoveMouse(X, Y);

client.Free;

bmp.Free;

end.[/scar]

Edited by Janilabo
Link to comment
Share on other sites

Beaten to it :) Few remarks though...

 

LoadFromStr is fairly redundant here as you can input the string directly into the TSCARBitmap constructor.

[wiki=SetClient]SetClient[/wiki] returns the previously set client, so you're calling activate on the wrong client (and I guess it also wasn't in the original script :P)

The old MoveMouse now translates to SetMousePos.

It's also good practice to use try...finally (though not a requirement because of the resource management)

 

So:

[scar]var

client: TSCARClient;

bmp: TSCARBitmap;

X, Y: Integer;

bx: TBox;

 

begin

ClearDebug;

bmp := TSCARBitmap.Create('deNrjYeBhAAIBAYGVazZEd2wwzZpmnj/PsmCuZcFsq4K5VoU' +

'zLfJmGWROnjhpyv///51KFmgn9plkTDXLmm6ePc0sZ45F1izjjBkq8T3q0X1ABSmda9Vju80' +

'zJ5jnzDCObVByS5C3DVSw81PwSN96/Pqz1x9OXHuhHNlqkjHFMnuGWkCBuIGtrLGTlKmbkJZ' +

'lfk37fzAonLJNK7HXJHOKbmyDtL6VjLmbgrmjrLkHv7Z1WWsfRI1ryTyjlG6T3FkqjsHSJi7' +

'yZs7SFu7SZq5ypo6iBi67Dh57/u6dZdYUw9Rei+wZ8hZe4kBDzBylzDxkzd1kzVwlTV0FNCx' +

'41C2tc2foZ0y2yJwub+0pZ+Ysb+ohbe4ia+YGtFTW3FXGzF3OyCa0fol26gTLrBnKngnSxrb' +

'Spp4y5k5QNWZu0ubuMoaWUzedVIvpMU2fYpbaJWFsB7bFGWiCrKmrrJmLrKmDjHXAp8//NZM' +

'6TVL6gIFsFNcmbmwvY2wvZeIoa+okaeIsYeZlmdr9/uf/rUfuyYQ0AoPIJHuqRfpETZ90Jbs' +

'QebsALZ8sy4x+k6ypACchnHA=');

try

client := TSCARWindowClient.Create(GetDesktopWindow);

SetClient(client).Free;

client.Activate;

bx := client.InputArea;

Wait(5000);

if FindBitmapTol(X, Y, bmp, bx.X1, bx.Y1, bx.X2, bx.Y2, 42) then

SetMousePos(X, Y);

finally

bmp.Free;

end;

end.[/scar]

 

(Note that the active client never has to be freed, it also can't be freed as there always has to be an active client.)

Edited by Freddy
Link to comment
Share on other sites

I have problem with conversion to 3.35, so litle script to convert:

var window1,window2,bmp : integer;

procedure SetMyWindowsAndBitmaps;
 begin
   FindWindowTitlePart('windowname1',false);
   Window1 := GetClientWindowHandle;
   FindWindowTitlePart('windowname2',false);
   Window2 := GetClientWindowHandle;
  bmp := LoadBitmap(ScreenPath+'mypicture.png');
 end;

begin

 SetMyWindowsAndBitmaps;

 SetClientWindowHandle(Window1);
 ActivateClient;
 writeln('im in window1');

 SetClientWindowHandle(Window2);
 ActivateClient;
 writeln('im in window1');

 setdesktopasclient;
 writeln('im on desktop');

 SetTargetBitmap(bmp);
 writeln('im in picture');

 setdesktopasclient;
 writeln('im on desktop again');

end;

Link to comment
Share on other sites

[scar]var

Bmp: TSCARBitmap;

WindowClient1, WindowClient2, DesktopClient: TSCARWindowClient;

BitmapClient: TSCARBitmapClient;

 

procedure SetMyWindowsAndBitmaps;

var

Windows: THwndArray;

begin

Windows := FindWindowsEx(GetDesktopWindow, 'windowname1', '', False, False, True);

if Length(Windows) > 0 then

WindowClient1 := TSCARWindowClient.Create(Windows[0]);

 

Windows := FindWindowsEx(GetDesktopWindow, 'windowname2', '', False, False, True);

if Length(Windows) > 0 then

WindowClient2 := TSCARWindowClient.Create(Windows[0]);

 

DesktopClient := TSCARWindowClient.Create(GetDesktopWindow);

 

Bmp := TSCARBitmap.Create('');

if Bmp.LoadFromPng(ScreenPath + 'mypicture.png') then

BitmapClient := TSCARBitmapClient.Create(Bmp);

end;

 

begin

SetMyWindowsAndBitmaps;

 

// Could be nil because the window may not have been found:

if WindowClient1 <> nil then

begin

SetClient(WindowClient1).Free; // Set client + free the old one

// SetClient is required to use colorfinding or mouse/keyboard I/O on the

// client, not required to activate it:

WindowClient1.Activate;

WriteLn('im in window1');

end;

 

if WindowClient2 <> nil then

begin

SetClient(WindowClient2); // Don't call Free or WindowClient1 would be freed

WindowClient2.Activate;

WriteLn('im in window2');

end;

 

SetClient(DesktopClient);

WriteLn('im on desktop');

 

// Could be nil because the image may not exists on the drive:

if BitmapClient <> nil then

begin

SetClient(BitmapClient);

WriteLn('im in picture');

end;

 

SetClient(DesktopClient);

WriteLn('im on desktop again');

 

// Free resources (NOT REQUIRED, good practice), SCAR does this itself if you

// do not do it

if WindowClient1 <> nil then

WindowClient1.Free;

if WindowClient2 <> nil then

WindowClient2.Free;

if BitmapClient <> nil then

BitmapClient.Free;

Bmp.Free;

// Do not free DesktopClient, a client always has to stay active!

end.[/scar]

Link to comment
Share on other sites

Center point to search outwards from?

 

Was going to point you to the wiki (http://wiki.scar-divi.com) but wouldn't you know it, it's not on there.

 

It hasn't been documented yet, but you're right. Before the functions that didn't return a TPA, passed that point through X and Y, but I didn't think that was very convenient, hence the separate parameters. -1, -1 will start from the center if I recall correctly.

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