Move mouse cursor

Mac OSX specific forum
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Move mouse cursor

Post 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()
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Move mouse cursor

Post 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.
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: Move mouse cursor

Post by Rinzwind »

btw why is CGWarpMouseCursorPosition(*xy.CGPoint) not working as expected? Don't understand.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Move mouse cursor

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply