diff --git a/Projects/SAMufasaGUI/testunit.pas b/Projects/SAMufasaGUI/testunit.pas index 2cef4b9..0dcf5dc 100644 --- a/Projects/SAMufasaGUI/testunit.pas +++ b/Projects/SAMufasaGUI/testunit.pas @@ -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; diff --git a/Tests/PS/plugintest.txt b/Tests/PS/plugintest.txt index dc1b70d..0d82666 100644 --- a/Tests/PS/plugintest.txt +++ b/Tests/PS/plugintest.txt @@ -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; diff --git a/Units/MMLAddon/PSInc/Wrappers/other.inc b/Units/MMLAddon/PSInc/Wrappers/other.inc index 18eae0d..5da0053 100644 --- a/Units/MMLAddon/PSInc/Wrappers/other.inc +++ b/Units/MMLAddon/PSInc/Wrappers/other.inc @@ -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; diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index 4e262ad..fe93d12 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -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;'); diff --git a/Units/MMLAddon/mmlpsthread.pas b/Units/MMLAddon/mmlpsthread.pas index e903add..6eacc79 100644 --- a/Units/MMLAddon/mmlpsthread.pas +++ b/Units/MMLAddon/mmlpsthread.pas @@ -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; diff --git a/Units/MMLCore/input.pas b/Units/MMLCore/input.pas index 0c04b3a..479d059 100644 --- a/Units/MMLCore/input.pas +++ b/Units/MMLCore/input.pas @@ -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); diff --git a/Units/MMLCore/window.pas b/Units/MMLCore/window.pas index 67b983b..9b216ef 100644 --- a/Units/MMLCore/window.pas +++ b/Units/MMLCore/window.pas @@ -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;