Setting the mouse location

Michael
Unregistered
 
Post: #1
Does anyone know of a way to have a program set the mouse location in C? The LMSetMouseLocation function in LowMem.h has been phased out in Carbon, and the Apple page says that it is impossible for an application to change the mouse location directly.

Background: I'm trying to program a Crystal-quest style mouse control for a game. Basically, to do that control style:

Store the location of the mouse
If the mouse moves, accelerate your ship in that direction
Store the new location of the mouse

So basically, moving the cursor accelerates in the direction that you moved it in. It's very intuitive, but the problem is that the cursor can end up moved all the way to one side of the screen, and will move no farther. So the work-around is to re-center the mouse each frame...
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Search the forums, this has been answered before.

You should really use absolute mouse deltas rather than moving the mouse.
Quote this message in a reply
Member
Posts: 104
Joined: 2002.04
Post: #3
Look in the CoreGraphics headers. its all in there.
Quote this message in a reply
ededed
Unregistered
 
Post: #4
Yup core graphics...

CGDirectDisplay.h
CGDisplayErr CGDisplayMoveCursorToPoint(CGDirectDisplayID display, CGPoint point)

I think I can get you an example of that in use...
Quote this message in a reply
ededed
Unregistered
 
Post: #5
http://www.geocities.com/ed72678954/index.html

Download JellyMouse and Space Goon (Just get Space Goon because its 1/10cool).
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #6
OMG, someone with the same idea as me. A little competition doesn't hurt, but this looks doubtful...

Here is the thread

"When you dream, there are no rules..."
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #7
Well I just had to post this solution, after just spending about 8 hours trying to figure out the same thing. Now if anyone looks at this post they might have an easier way of setting the mouse position.

CGPoint pos;
CGSetLocalEventsSuppressionInterval(0);
CGWarpMouseCursorPosition(pos);

I'm trying to port the gameTutorials SDL openGL tutorials to Cocoa. Very good learning experience.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
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,568 Apr 3, 2009 02:40 PM
Last Post: Gillissie
  polling mouse location? alloca 1 2,521 Jan 22, 2009 04:14 PM
Last Post: ThemsAllTook
  Cocoa: Mouse location while dragging window Fenris 4 5,064 Jul 14, 2005 04:46 PM
Last Post: Fenris
  Getting mouse location Steven 25 8,119 Aug 3, 2003 07:24 PM
Last Post: OneSadCookie
  mouse location woes kelvin 4 4,721 Dec 6, 2002 05:50 PM
Last Post: wally