• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting mouse cursor position
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting mouse cursor position


  • Subject: Re: Getting mouse cursor position
  • From: Greg Parker <email@hidden>
  • Date: Fri, 6 May 2011 16:31:45 -0700

On May 6, 2011, at 3:55 PM, eveningnick eveningnick wrote:
> I am searching for the way to find a cursor's position on the screen.
>
> I tried to use method -hotSpot of NSCursor, but it returns
>> sc x=-2057825613, y=0
>
> -(IBAction)timeHandler:(id)timer {
>        //NSCursor *sc = [NSCursor currentSystemCursor];
> 	NSCursor *sc = [NSCursor currentCursor];
> 	NSLog(@"sc x=%d, y=%d", [sc hotSpot].x, [sc hotSpot].y);
> }
>
> What may be wrong here?
> I can successfully retrieve cursor's image though. But not the position. Why?

-[NSCursor hotSpot] tells you nothing about the mouse position. The hotSpot is the location inside the cursor image of the tip of the arrow.

If you need the mouse position at the time of some event, use -[NSEvent locationInWindow].
If you need the mouse position "now" inside some window, use -[NSWindow mouseLocationOutsideOfEventStream].
If you need the mouse position "now" with neither an event nor a window, use +[NSEvent mouseLocation].


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Getting mouse cursor position (From: eveningnick eveningnick <email@hidden>)

  • Prev by Date: Re: Getting mouse cursor position
  • Next by Date: Re: Getting mouse cursor position
  • Previous by thread: Re: Getting mouse cursor position
  • Next by thread: Re: Getting mouse cursor position
  • Index(es):
    • Date
    • Thread