Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 613
Roland Kossow Avatar asked Oct 28 '12 11:10

Roland Kossow


1 Answers

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

like image 113
David Peters Avatar answered Sep 20 '22 07:09

David Peters