lotus



previous page: 3.1) How do I read the modifier keys of the keyboard? (User / Machine interaction - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 3.3) My menus don't show up in the menu bar (User / Machine interaction - Mac Programming)

3.2) How do I move the mouse cursor to a specific position? (User / Machine interaction - Mac Programming)




Description

This article is from the Mac Programming FAQ, by Jon Watte h+@austin.metrowerks.com with numerous contributions by others.

3.2) How do I move the mouse cursor to a specific position? (User / Machine interaction - Mac Programming)

Wait! Don't do it! There has to be a better way!

If you feel you HAVE to do it (for a game or VERY special simulation
situation) you can use the Cursor Device Manager documented in the tech
notes on <ftp.apple.com>. If that manager is not installed, as it's not
on older Macs, you can use the following code:

You need to have some low-memory globals defined. they may be defined
in SysEqu.h.

#define MTemp 0x828
#define RawMouse 0x82c
#define CrsrNewCouple 0x8ce

Note that CrsrNewCouple is actually a combination of two globals, just
to make our life slightly easier.

The code I use to move the mouse is:

*code*
void
MoveMouseTo ( Point where ) {
  
    HideCursor ( ) ;
    * ( Point * ) RawMouse = where ;
    * ( Point * ) MTemp = where ;
    * ( short * ) CrsrNewCouple = -1 ;
    ShowCursor ( ) ;
}
*end*

You need to hit a couple more global variables if you want this to work
properly in a multiple-monitor system, but i forget what they are
offhand. poke through SysEqu.h, and you should be able to figure it out
without a problem.

On the PowerPC, these lo-mem globals may not be available for native
applications; however, all Power Macintoshes implement the Cursor Device
Manager. All Macs made after March '93 (including Centris 650 and 610)
implement the Cursor Device Manager, in fact.

There is also a file on nada.kth.se:pub/hacks/mac-faq/MoveMouse.c which
shows how to use the Cursor Device Manager, written by an excellent
Apple engineer. Grab!

Careful, version 1.0 of the Universal Header "CursorDevices.h" file was
completely incorrect. Use 2.0a3 or later.

 

Continue to:















TOP
previous page: 3.1) How do I read the modifier keys of the keyboard? (User / Machine interaction - Mac Programming)
  
page up: Mac Programming FAQ
  
next page: 3.3) My menus don't show up in the menu bar (User / Machine interaction - Mac Programming)