Have a look at the package http://wiki.freepascal.org/MouseAndKeyInput
It has everything in it to do what you want.
Error: ld: library not found for -lXtstFrom http://wiki.freepascal.org/MouseAndKeyInput
Gtk1/2
- needs Xtst library
This function is not recommended for general use because of undocumented special cases and undesirable side effects. The recommended replacement for this function is CGEventCreateMouseEvent, which allows you to create a mouse event and customize the event before posting it to the event system.
Error: ld: library not found for -lXtstFrom http://wiki.freepascal.org/MouseAndKeyInputQuoteGtk1/2
- needs Xtst library
Otherwise you can view carbonmouseinput.pas (https://github.com/alrieckert/lazarus/blob/master/components/mouseandkeyinput/carbonmouseinput.pas) yourself and see how it's done.
BTW. The sourcecode in CGRemoteOperations.pas says CGPostMouseEvent is deprecated and you should use CGEventCreateMouseEvent instead. (That wasn't in the C code, was it :D)
According to Apples documentation, CGPostMouseEvent is indeed deprecated:
https://developer.apple.com/documentation/coregraphics/1541785-cgpostmouseeventQuoteThis function is not recommended for general use because of undocumented special cases and undesirable side effects. The recommended replacement for this function is CGEventCreateMouseEvent, which allows you to create a mouse event and customize the event before posting it to the event system.
{ This function is obsolete. Use `CGEventCreateMouseEvent' instead. Synthesize a low-level mouse-button event on the local machine. The parameter `mouseCursorPosition' specifies the new coordinates of the mouse in global display space. Pass true for `updateMouseCursorPosition' if the on-screen cursor should be moved to the location specified in the `mouseCursorPosition' parameter; otherwise, pass false. The parameter `buttonCount' specifies the number of mouse buttons, up to a maximum of 32. Pass true for `mouseButtonDown' to specify that the primary or left mouse button is down; otherwise, pass false. The remaining parameters are Boolean values that specify whether the remaining mouse buttons are down (true) or up (false). The second value, if any, should specify the state of the secondary mouse button (right). A third value should specify the state of the center button, and the remaining buttons should be in USB device order. Based on the values entered, the appropriate mouse-down, mouse-up, mouse-move, or mouse-drag events are generated, by comparing the new state with the current state. } function CGPostMouseEvent( mouseCursorPosition: CGPoint; updateMouseCursorPosition: boolean_t; buttonCount: CGButtonCount; mouseButtonDown: boolean_t; ... ): CGError; external name '_CGPostMouseEvent'; (* CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_6, __IPHONE_NA, __IPHONE_NA) *)