Page 1 of 1

Move mouse cursor

Posted: Tue Dec 03, 2019 11:11 am
by Rinzwind
Any reason why this code does not position the mouse at the center of the screen?

Code: Select all

EnableExplicit

ImportC ""
  CGWarpMouseCursorPosition(p)
  CGMainDisplayID()
  CGDisplayPixelsWide(did)
  CGDisplayPixelsHigh(did)
  CGEventSourceCreate(state)
  CGEventSourceSetLocalEventsSuppressionInterval(event, seconds)  
EndImport

Procedure Test()
  Protected mouseLoc.CGPoint
  
  Protected did = CGMainDisplayID()
  mouseLoc\x = CGDisplayPixelsWide(did) / 2
  mouseLoc\y = CGDisplayPixelsHigh(did) / 2
  CGWarpMouseCursorPosition(mouseLoc)
;   Protected evs = CGEventSourceCreate(0)
;   CGEventSourceSetLocalEventsSuppressionInterval(evs, 0)  
EndProcedure

Test()

Re: Move mouse cursor

Posted: Tue Dec 03, 2019 11:43 am
by Rinzwind
Ok, this one does work CGWarpMouseCursorPosition(x.CGFloat, y.CGFloat)

But still, pity structure support for API on macOS is lacking.
CGWarpMouseCursorPosition(*xy.CGPoint) is also a no-go (wrong result?). Structure return value too.

Re: Move mouse cursor

Posted: Tue Dec 03, 2019 4:37 pm
by Rinzwind
btw why is CGWarpMouseCursorPosition(*xy.CGPoint) not working as expected? Don't understand.

Re: Move mouse cursor

Posted: Tue Dec 03, 2019 4:44 pm
by wilbert
Rinzwind wrote:btw why is CGWarpMouseCursorPosition(*xy.CGPoint) not working as expected? Don't understand.
Because PureBasic passes structures by reference and a lot of macOS functions (including this one) need the structure to be passed by value.