[comp.sys.mac] Cursor Control

rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) (09/20/87)

   Does anybody know how to move the cursor from within an application. (I
don't mean with the mouse, but by actually changing the coordinates with a
program). I also need to know if it is possible to constrain the motion of
the cursor to a smaller rectangle than the screen.
   Any ideas?

                    Rob Johnston
                    rj0z+@andrew.cmu.edu

oster@dewey.soe.berkeley.edu (David Phillip Oster) (09/23/87)

In article <sVJ1zsy00UgLwe00=B@andrew.cmu.edu> rj0z+@andrew.cmu.edu (Robert George Johnston, Jr.) writes:
>   Does anybody know how to move the cursor from within an application. (I
>don't mean with the mouse, but by actually changing the coordinates with a
>program). 

Apple _strongly_ recommends that you not do this. Apple has promised
to deimplement the current mechanism for doing this.  The current
mechanism is documented in Inside Macintosh Vol. 1, at the end of the
Event Manager section. This is the section on "journaling", and it is
this mechanism that I used so that my digitizing tablet drivers can
move the mouse cursor.  If it is going to work with arbitrary
programs, you must do a _lot_ of work to patch the ROMs to get around
bugs in people's application programs. Among the programs that had
bugs with this method were early versions of the ImageWriter Printer
driver.

>I also need to know if it is possible to constrain the motion of
>the cursor to a smaller rectangle than the screen.

You can get the seeming of moving the cursor under program control by
calling HideCursor(), and doing your own graphics to do your own mouse
tracking. In general you should do this only under very tightly
constrained circumstances, since it makes living under a multi-tasking
environment painful.


--- David Phillip Oster            --This space for rent.
Arpa: oster@dewey.soe.berkeley.edu --Your message could go here!
Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu

wade@sdacs.ucsd.EDU (Wade S. Blomgren) (09/23/87)

In <sVJ1zsy00UgLwe00=B@andrew.cmu.edu>, (Robert George Johnston, Jr.) writes:
>    Does anybody know how to move the cursor from within an application. (I
> don't mean with the mouse, but by actually changing the coordinates with a
> program). I also need to know if it is possible to constrain the motion of
> the cursor to a smaller rectangle than the screen.

In answer to the second question, there is a low memory global called 
CrsrPin, the cursor pinning rectangle, at location Ox834.  To restrict 
the movement of the cursor to a given rectangle, save the contents of 
CrsrPin somewhere, and insert your own values. (Please restore the old 
values when your program exits). 

eg:
extern	Rect CrsrPin : Ox834;
	Rect OldCrsrPin,
	NewRect = { 10,10,20,20 };

OldCrsrPin = CrsrPin;
CrsrPin = NewRect;
/* do your thing here */
CrsrPin = OldCrsrPin;


My follow up questions are: 

How can you (easily) induce the new pinning rectangle to take effect 
without mouse movement? (This would answer question number 1)
Where does CrsrPin fit in when you have more than one monitor?

Wade Blomgren
UCSD ACS (wade@sdacs.ucsd.edu)

wade@sdacs.ucsd.EDU (Wade S. Blomgren) (09/23/87)

This is sort of a self flame to follow up my response about the
cursor pinning rectangle. Please note that the mechanism I suggested
is just a _hack_ to get the explicit result asked for. (Somebody
once asked me how I thought MacLanding accomplished this, and I
dug around and found CrsrPin.) I have no idea what Apple's feelings
are concerning use of this global, and I suspect that anything you
do with it could be hazardous when used in conjunction with things
like MultiFinder, unless you are very careful.

Wade Blomgren
wade@sdacs.ucsd.edu

hpai%mindblow.uucp@utah-cs.UUCP (HP AI User) (09/23/87)

In article <sVJ1zsy00UgLwe00=B@andrew.cmu.edu> rj0z+@andrew.cmu.edu writes:
>   Does anybody know how to move the cursor from within an application. (I
>don't mean with the mouse, but by actually changing the coordinates with a
>program). I also need to know if it is possible to constrain the motion of
>the cursor to a smaller rectangle than the screen.

I spent a while figuring this out last year, and the answer is yes, but
only if you want to sacrifice compatibility.  There is a set of
undocumented low memory globals on the Mac 128K, 512K, and Plus that
store cursor info, but I have no idea if they're available on the SE or
the II, and there's no guarantee that they'll be there on future
machines.

CrsrPin at $834 is a rectangle the cursor is pinned to, initially the
size of the screen (I don't know about multiple-screen systems).  If you
make it larger than the screen the Mac crashes.  When changing cursor
info, set the byte-size boolean CrsrNew at $8CE and wait a tick for the
cursor to be updated.  CrsrCouple, a byte-size boolean at $8CF, is true
if the cursor is coupled to the mouse.  Unset it if you don't want the
user using the mouse.  I couldn't figure out how to move the cursor
other than temporarily setting CrsrPin to a tiny rectangle at the point
I wanted the cursor.

Carefully consider why you want to move the cursor.  I used a system
called Geos on my friend's Commodore 64 that always helpfully moved the
cursor to the point where it thought I wanted it.  It drove me crazy.
In addition, restricting the cursor's movement has shades of (gasp)
MODES, and works against MultiFinder.  I think Apple has good reason not
to document the cursor routines.

-----
Lee Choquette				u-lchoqu@ug.utah.edu
University of Utah Computer Center	CHOQUETTE@UTAHCCA.BITNET
MEB 3440				utah-gr!utah-ug!u-lchoqu
Salt Lake City, UT  84112		(801) 581-8504

hpai%mindblow.uucp@utah-cs.UUCP (HP AI User) (09/23/87)

I haven't played with this stuff recently, but as I remember...
There is a set of low-memory globals that control the cursor on the screen.

Name        Location    Description
--------    --------    ----------------------------------------------------
MTemp       $828        A point that describes the cursor's immediately
                        previous position on the screen.
RawMouse    $82C        A point that describes the cursor's current position
                        on the screen.  The difference between MTemp and
                        RawMouse determines the velocity of the cursor.
CrsrPin     $834        A pinning rectangle for the cursor.  The cursor must
                        stay within CrsrPin.
CrsrRect    $83C        Cursor hit rectangle.  I've never played with this.
TheCrsr     $844        The current cursor's data, mask, and hot spot.
CrsrAddr    $888        A pointer to the screen memory address covered by the
                        cursor (at least, this is what it is on a Mac Plus and
                        probably an SE.  This doesn't make sense on a Mac II).
CrsrSave    $88C        64 bytes of screen data covered by the cursor -- what's
                        under the cursor.
CrsrVis     $8CC        Boolean: is the cursor visible?
CrsrBusy    $8CD        Boolean: is the cursor locked out?
CrsrNew     $8CE        Boolean: has the cursor changed?
CrsrCouple  $8CF        Boolean: is the cursor coupled to the mouse?
CrsrState   $8D0        Cursor nesting level, used by HideCursor and
                        ShowCursor, I think.
CrsrObscure $8D2        Boolean: is the cursor obscured?
CrsrScale   $8D3        Boolean: is the cursor scaled?
MouseMask   $8D6        A point that is ANDed with cursor coordinates.
MouseOffset $8DA        A point that is added to the cursor coordinates.  Like
                        an upper left-hand corner for the cursor's movement.
CrsrThresh  $8EC        Velocity threshhold used for mouse scaling.
JCrsrTask   $8EE        The address of the routine that controls the movement
                        of the mouse.  When I last checked, this was $401E86
                        (Mac Plus, pre-System 4.1 days).

Probably more than you wanted to know.  Anyway, about program-controlled
cursor movement.  First, store some non-zero value in CrsrBusy.  This "locks
out" the cursor and should prevent the JCursTask proc from moving the cursor.
Next, store the point at which you want the cursor in MTemp and RawMouse.  And
finally, clear CrsrBusy.  The cursor should appear where you want it.

This makes for a good April Fool's joke.  Another good one is to write an INIT
that stores $00140000 in MouseOffset.  I did this once... my coworker still
won't let me near his hard disk :-).

As I said, it has been a while since I've looked at the cursor handling stuff.
I wouldn't be surprised if System 4.1 installs its own JCrsrTask for the
variable-speed mouse scaling, and only Apple knows what a Mac II does.  But I
hope this information is at least interesting, if not entirely useful.

Credit where credit is due: Most of the information in this article came from
Scott Knaster's great book, "How to Write Macintosh Software."

-----
Eric Eide
UUCC Consultant

singer@endor.harvard.edu (Andrew Singer) (09/23/87)

I'm not sure exactly how to position the mouse cursor; I do know that
it's not really a kosher thing to do.

However, it is possible to clip the cursor's movement to an arbitrary rectangle

That rectangle is defined in a low-memory global. Unfortunately, Inside Mac
Volume 3 doesn't list this global, but you should be able to find it in
the assembler equates that come with either the MPW assembler or the Consulair
assembler.

		--Rich

**Note: The opinions stated herein are my own and do not represent the
opinions of my employer (THINK Technologies, Inc.)

Richard M. Siegel
Customer Support Representative
THINK Technolog2:3ercee s

oster@dewey.soe.berkeley.edu (David Phillip Oster) (09/25/87)

In article <445@sdacs.ucsd.EDU> wade@sdacs.ucsd.EDU (Wade S. Blomgren) writes:
>In answer to the second question, there is a low memory global called 
>CrsrPin, the cursor pinning rectangle, at location Ox834.  

This does not work on at least one model of Macintosh. The Macintosh XL does
not use CrsrPin to track the mouse with a cursor on the screen.


--- David Phillip Oster            --My Good News: "I'm a perfectionist."
Arpa: oster@dewey.soe.berkeley.edu --My Bad News: "I don't charge by the hour."
Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu