Roland Kossow
Roland Kossow

Reputation: 103

Setting the mouseposition in a crossplatform way with Firemonkey 2 (FMX2)

In Firemonkey 2 (FMX2) there is the interface

IFMXMouseService = interface(IInterface) ['{2370205F-CF27-4DF6-9B1F-5EBC27271D5A}']

The interface just has a GetMousePos function. But how can I set the mouseposition in a crossplattform way? Any ideas anybody?

The best idea I came up with yet is to do a conditionaly compile until the possibility is existing in FMX - but I do not know how to set the mouseposition via Delphi for MACOSX. I would be thankful for any help.

Upvotes: 6

Views: 1226

Answers (1)

David Peters
David Peters

Reputation: 220

Here is the procedure you need. You will have to add macapi.coregraphics and macapi.cocoatypes to your uses clause.

procedure setmousepos(x,y:single);

var aNSPoint:NSPoint;

begin
  aNSPoint.x:=x;
  aNSPoint.y:=y;
  CGWarpMouseCursorPosition(aNSPoint);
end;

You could of course pass a TPointF in place of X,Y but you still need to set up the NSPoint X and Y separately as NSPoint is different to TPointF.

Regards

Dave Peters
DP Software
www.dpsoftware.com/firemonkey

Upvotes: 3

Related Questions