1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-12-22 07:18:51 -05:00

Made smart work again, and make the mouse move outside target (on windows).

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@429 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-01-18 22:30:29 +00:00
parent d6014fe316
commit 5995ac8bde
7 changed files with 74 additions and 11 deletions

View File

@ -42,7 +42,7 @@ uses
ColorBox, about, framefunctionlist, ocr, updateform, simbasettings;
const
SimbaVersion = 427;
SimbaVersion = 429;
type
@ -531,6 +531,7 @@ begin
ScriptThread := TMMLPSThread.Create(True,@CurrentSyncInfo);
{$IFNDEF TERMINALWRITELN}
ScriptThread.SetDebug(@formWriteln);
ScriptThread.DebugMemo := Self.Memo1;
{$ENDIF}
ScriptThread.SetPSScript(CurrScript.SynEdit.Lines.Text);
DbgImgInfo.DispSize := @DebugImgForm.DispSize;

View File

@ -1,6 +1,54 @@
program new;
{.LoadDLL libsmart}
function IsKeyDown(C:Char): Boolean;
begin
Result := SmartIsKeyDown(ord(c));
end;
procedure MoveMouse(x, y: Integer);
begin
SmartMoveMouse(x, y);
end;
procedure HoldMouse(x, y: Integer; left: Boolean);
begin
SmartHoldMouse(x, y, left);
end;
procedure ReleaseMouse(x, y: Integer; left: Boolean);
begin
SmartReleaseMouse(x, y, left);
end;
procedure KeyUp(key: Byte);
begin
If Key = 13 Then
Key := 10;
SmartReleaseKey(key);
end;
procedure KeyDown(key: Byte);
begin
If Key = 13 Then
Key := 10;
SmartHoldKey(key);
end;
procedure SendKeys(S: String);
begin
SmartSendKeys(S);
end;
procedure GetMousePos(var x, y: Integer);
begin
SmartGetMousePos(x, y);
end;
function GetColor(x, y: Integer): Integer;
begin
result:= SmartGetColor(x, y);
end;
var
w,h:integer;

View File

@ -42,6 +42,12 @@ begin
end;
{$endif}
procedure ClearDebug;
begin
if Assigned(CurrThread.DebugMemo) then
CurrThread.Synchronize(@CurrThread.DebugMemo.Clear);
end;
procedure SaveScreenshot(FileName: string);
var
w,h : integer;

View File

@ -22,7 +22,7 @@
}
AddFunction(@ThreadSafeCall,'function ThreadSafeCall(ProcName: string; var V: TVariantArray): Variant;');
AddFunction(nil,'procedure writeln(x);'); //We use special function for this
AddFunction(nil,'procedure Writeln(x);'); //We use special function for this
{ DTM }
SetCurrSection('DTM');
@ -41,6 +41,7 @@ AddFunction(@ps_addpDTM, 'function AddpDTM(d: pDTM): Integer;');
{maths}
SetCurrSection('Math');
AddFunction(nil,'function Round(e:extended) : integer');
AddFunction(@ceil,'function ceil(e : extended) : integer');
AddFunction(@power,'function pow(base,exponent : extended) : extended');
AddFunction(@max,'function Max(a, b: Integer): Integer;');
@ -92,6 +93,7 @@ AddFunction(@DrawBitmapDebugImg,'procedure DrawBitmapDebugImg(bmp: integer);');
AddFunction(@GetDebugBitmap,'function GetDebugBitmap: integer;');
AddFunction(@Random,'function Random(Int: integer): integer;');
AddFunction(@NewThreadCall,'function NewThreadCall(procname : string) : cardinal');
AddFunction(@ClearDebug,'procedure ClearDebug;');

View File

@ -101,6 +101,7 @@ type
PSScript : TPSScript; // Moved to public, as we can't kill it otherwise.
Client : TClient;
StartTime : LongWord;
DebugMemo : TMemo;
SyncInfo : PSyncInfo; //We need this for callthreadsafe
ErrorData : PErrorData; //We need this for thread-safety etc
property OnError : TOnError read FOnError write FOnError;

View File

@ -282,17 +282,22 @@ var
{$ENDIF}
w,h: integer;
begin
{$IFDEF MSWINDOWS}
GetWindowRect(Window.TargetHandle, Rect);
x := x + rect.left;
y := y + rect.top;
if (x<0) or (y<0) then
writeln('Negative coords, what now?');
Windows.SetCursorPos(x, y);
{$ENDIF}
{$IFDEF LINUX}
// This may be a bit too much overhead.
Window.GetDimensions(w, h);
if (x < 0) or (y < 0) or (x > w) or (y > h) then
raise Exception.CreateFmt('SetMousePos: X, Y (%d, %d) is not valid', [x, y]);
{$IFDEF MSWINDOWS}
GetWindowRect(Window.TargetHandle, Rect);
Windows.SetCursorPos(x + Rect.Left, y + Rect.Top);
{$ENDIF}
{$IFDEF LINUX}
Old_Handler := XSetErrorHandler(@MufasaXErrorHandler);
XWarpPointer(Window.XDisplay, 0, Window.CurWindow, 0, 0, 0, 0, X, Y);
XFlush(Window.XDisplay);

View File

@ -719,8 +719,8 @@ function TMWindow.SetTarget(ArrPtr: PRGB32; Size: TPoint): integer; overload;
begin
if Self.Frozen then
raise Exception.CreateFMT('You cannot set a target when Frozen',[]);
OnSetTarget(w_ArrayPtr,self.TargetMode);
Self.SetDesktop;//Set the underlaying window to desktop for key-sending etc..
OnSetTarget(w_ArrayPtr,self.TargetMode);
Self.ArrayPtr := ArrPtr;
Self.ArraySize := Size;
end;