Getting mouse location

Member
Posts: 370
Joined: 2002.04
Post: #1
How do I get the mouse location? I don't really want to use the mouseMoved events, as I have one place in which I need to know where the mouse is at that instant, and thus it seems to be a place for query-driven mousing instead of event-driven. And, there's no NSMouse object Wink ([NSMouse whereAmI] hehe)

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #2
I don't know about Cocoa, but there's always Carbon's GetMouse() function.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
anarchie
Unregistered
 
Post: #3
Code:
NSPoint mouseLoc = [NSEvent mouseLocation];
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #4
Thanks.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #5
Is there a similar thing for keys? NSEvent doesn't seem to have any more. Key repeat delays are screwing with my game... Sad

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
Just keep an array of which keys are pressed, set the appropriate element to true when a key goes down and to false when the key comes back up again.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #7
How do I get key up events, then?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
If you're using the standard NSResponder stuff, override -keyUp:
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #9
Ok, I don't understand something here. When I looked for the documentation on keyUp, I saw that there was a corresponding keyDown method. I was previously using performKeyEquivalent. Why does keyDown not work? It just beeps at me...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 177
Joined: 2002.08
Post: #10
Have you set the receiving view as first responder?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
You need to become the first responder.
Quote this message in a reply
Member
Posts: 304
Joined: 2002.04
Post: #12
check to make sure that your view is the first responder.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #13
Heh, nice timing... Thanks. That did it. I'll try the array idea now...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #14
Is there a better method than BOOL keyArray[65536]? Do I have to cover every unichar?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #15
If you use keyCodes, there are only 128... but really you only need remember the state of keys you care about. I generally do it as an array of "game inputs" rather than as an array of keys.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  ending location from angle and speed Kazooless 5 4,335 Apr 3, 2009 02:40 PM
Last Post: Gillissie
  polling mouse location? alloca 1 2,401 Jan 22, 2009 04:14 PM
Last Post: ThemsAllTook
  Cocoa: Mouse location while dragging window Fenris 4 4,857 Jul 14, 2005 04:46 PM
Last Post: Fenris
  Setting the mouse location Michael 6 4,105 Jun 22, 2003 03:39 AM
Last Post: reubert
  mouse location woes kelvin 4 4,587 Dec 6, 2002 05:50 PM
Last Post: wally