Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Keeping the mouse-pointer on one screen in dual monitor setup?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keeping the mouse-pointer on one screen in dual monitor setup?

>Now when the pointer reaches the left border of the GameScreen it jumps over
>to the second screen on monitor 2. The problem: If the screen size on
>monitor 2 is smaller than on monitor 1 then the mouse Y move area is also
>smaller and the pointer never reaches the GameScreen's Y border, even if I
>handle the mouse-coords relative to the port.
>The only solution I've found is to set the mouse coords manually and
>calculation delta x and delta y but this doesn't work with MacOS X.
>Is there a way to solve is problem without using the cursor device???

Hi, I found this response in the archives from 11/6/00:


It turns out that the mouse delta API is in the CGDirectDisplay API and
not Carbon Events, although the mouse moved Carbon Event is required to
make things come out right.

Take a look at CGDirectDisplay.h in the CoreGraphics framework. There
is a function that looks like this:

void CGGetLastMouseDelta (CGMouseDelta * deltaX, CGMouseDelta *deltaY );

The typical usage would be to install a Carbon Event handler for mouse
moved events (even if you aren't using Carbon Events for the rest of
your event handling) and then call CGGetLastMouseDelta for each moved

VERY IMPORTANT: note that CGGetLastMouseDelta does NOT reset after you
call it. If you simply call CGGetLastMouseDelta in your idle loop, for
example, you will get repeats of the same mouse delta until the mouse
moves again. That is probably not what you want... In order to keep the

deltas in sync with the mouse moves you should use CGGetLastMouseDelta
in conjunction with the mouse moved Carbon Event.

Also note that if you install the event handler for a window, the mouse
moved events will only be sent while the mouse is over your window. For

most full-screen games, that isn't a problem since the blanking window
covers the whole screen. If you need to use a smaller window and still
want to get mouse moved events, you can install the handler for the
application and receive mouse moved events as long as your application
is front-most.


Perhaps you can keep a number with the accumulation of these deltas and
pin it at some maximum. That way, even if they scroll onto the other
monitor, the moment they start moving back, that number will start
reducing again. It should fill like they are pinned on any sized screen,
for instance, 640x480. You could aso draw your own sprite cursor to make
it look like it is pinned (but it would probably quickly become out of
synch with the real cursor position as soon as the cursor bumped the edge
of the screen). Actually, this is sort of a serious problem that we will
all be dealing with at some point...hope this helps,

Zack Morris
Z Sculpt Entertainment

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.