• 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: Gregory Weston <email@hidden>
  • Date: Sat, 07 May 2011 15:56:40 -0400

On May 7, 2011, at 13:28, Nick wrote:

> 2011/5/7 Gregory Weston <email@hidden>:
>> eveningnick wrote:
>>
>>> Hello
>>> 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?
>>
>> Aside from the fact that you're treating it as the wrong data type, as has been pointed out, this is not the right method for your goal. The hotSpot method returns the location of the point within the cursor image that represents where the mouse is onscreen. Effectively it controls where the 2D image of the cursor is drawn relative to the point that is the mouse's current location.
>>
>> What you want is NSWindow's mouseLocationOutsideOfEventStream. Or preferably, if you have an event, then NSEvent's mouseLocation.
>
> Gregory,
> what do you mean by "if you have an event"? Could you elaborate on it please?

Well, part of what you should take away from that is that I've been operating on too little sleep this week and got two different NSEvent methods confused as a result.

You don't need to have an NSEvent instance for mouseLocation. You do for locationInWindow.

Greg
_______________________________________________

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: 
 >Re: Getting mouse cursor position (From: Gregory Weston <email@hidden>)
 >Re: Getting mouse cursor position (From: Nick <email@hidden>)

  • Prev by Date: Re: A Simple and Complete RunLoop Example
  • Next by Date: Communicate Between CocoaAsyncSocket and Java Socket
  • Previous by thread: Re: Getting mouse cursor position
  • Next by thread: Getting mouse cursor position
  • Index(es):
    • Date
    • Thread