Professional Web Applications Themes

Restricting Mouse Movement...possible? - Mac Programming

Hi...I'm writing a game (in straight-C, Carbon, CW8, meant for OS9 and OSX). When the game starts, the mouse (cursor) is hidden, and the (invisible) position of the mouse is used to control aspects of the game. The game works like a charm. The problem comes in if the user moves the (still invisible) mouse into various important areas of the screen... 1 - If the user is running in OSX and has the dock hidden, and happens to move the mouse in the area normally used to activate the dock, the dock activates (as it should, but not as ...

  1. #1

    Default Restricting Mouse Movement...possible?

    Hi...I'm writing a game (in straight-C, Carbon, CW8, meant for OS9 and
    OSX). When the game starts, the mouse (cursor) is hidden, and the
    (invisible) position of the mouse is used to control aspects of the
    game. The game works like a charm.

    The problem comes in if the user moves the (still invisible) mouse into
    various important areas of the screen...

    1 - If the user is running in OSX and has the dock hidden, and happens
    to move the mouse in the area normally used to activate the dock, the
    dock activates (as it should, but not as I would want)

    2 - If the user has a visible dock, my app is smart enough to respect
    the position of the dock and not put a window on top of it, but moving
    the (invisible) mouse onto the dock causes the cursor to reappear
    (again, as it should, but not as I would want.)

    3 - Also, If the user moves the (invisible) cursor into one of the hot
    corners to activate a screen saver, for instance, the screen saver
    activates. (again, as it should, but not as I want.)

    If, while the game is running and the cursor is hidden, I could
    magically prevent the mouse coordinates from ever going outside the
    content area of my window, these problems would be solved. (When the
    app is paused, the mouse would be visible again, and could travel
    anywhere.)

    Is it possible to control the mouse like that?

    f my window (which might be any size, full screen, or a small window)
    happened to have screen coordinates of xmin, xmax, ymin, ymax...I'd
    like to write (in pseudo code) such as this...(where xpos and ypos are
    the mouse coordinates)

    if (xpos < xmin)
    xpos = xmin
    if (xpos > xmax)
    xpos = xmax
    if (ypos < ymin)
    ypos = ymin
    if (ypos > ymax)
    ypos = ymax

    Is there a way to constrain the mouse so that it's impossible to stray
    beyond a programmed area until freed?

    Is there another way to avoid the problems above?

    (Note: I believe SetSystemUIMode and CGDisplayCapture come close to
    what I want, but I think both of those are OSX-only, and not available
    for use in Carbon and OS9???)

    Any help appreciated...

    Thanks!
    Bill Guest

  2. #2

    Default Re: Restricting Mouse Movement...possible?

    In article <050520041145561941%com>, com
    says... 

    I believe the normal thing to do is to centre the cursor, determine how
    far it has moved within a small time period and then re-centre the
    cursor. If the time period is small enough the user won't be able to
    move the mouse far enough to hit a hot point.
    James Guest

  3. #3

    Default Re: Restricting Mouse Movement...possible?

    Well, I guess that's part of what I'm asking...how do you actually
    "centre the cursor"?

    Am I forgetting a simple Mac call that lets you position the cursor
    (mouse) anywhere?

    (The whole point of my question was how to prevent a roving, and
    invisible mouse, to move over the dock, or a screensaver hotpoint. If I
    could just control the position of the cursor as you suggest, that's
    exactly what I'm looking for, but how? I know in days past there was a
    hard-coded global for mouse position that you could mess with, but I'm
    quite sure that that's either no longer available or totally frowned on
    nowadays.) So, I might have misunderstood you, but how did you intend
    to "centre the cursor"?

    THANKS!


    In article <Individual.NET>, James
    Weatherley <net> wrote:
     
    >
    > I believe the normal thing to do is to centre the cursor, determine how
    > far it has moved within a small time period and then re-centre the
    > cursor. If the time period is small enough the user won't be able to
    > move the mouse far enough to hit a hot point.[/ref]
    Bill Guest

  4. #4

    Default Re: Restricting Mouse Movement...possible?

    I don't think you can do it the same way in both 9 and X.

    In 9 it's relatively simple, just poke the new location into low memory and
    set a flag to tell the system it's changed. I don't have it here, but I can
    send you some code to do it later.

    There used to be an officially approved way (involving creating a phantom
    mouse device and moving that) but you REALLY don't want to go there. IIRC,
    it was designed around '94 for ADB machines. I used it for a Control Panel
    called NudgeMouser many moons ago and found it complicated and challengingly
    under doented.



    On X you obviously can't stick anything in low memory. There is an API
    (rumored to have been added unwillingly and under extreme duress by the
    development community) that supposedly lets you control the pointer. Search
    developer.apple.com for
    CGDisplayMoveCursorToPoint Moves the cursor to a specified point
    relative to the display origin (the upper left corner of the display).


    It's in Quartz Services, along with a few other mouse utilities. I once
    tried to use a related API to access the screen directly in OS X (didn't
    work) but that was a while back so maybe it's better now.

    Good luck.

    Paul




    "Bill" <com> wrote in message
    news:060520041147363027%com... [/ref][/ref]
    into 
    > >
    > > I believe the normal thing to do is to centre the cursor, determine how
    > > far it has moved within a small time period and then re-centre the
    > > cursor. If the time period is small enough the user won't be able to
    > > move the mouse far enough to hit a hot point.[/ref][/ref]


    Paul Guest

  5. #5

    Default Re: Restricting Mouse Movement...possible?

    In article <supernews.com>,
    "Paul" <com> wrote:
     

    Alternative options that might or might not be better for what you
    intend to do are CGWarpMouseCursorPosition and CGPostMouseEvent. See

    <http://developer.apple.com/doentation/GraphicsImaging/Reference/Quart
    z_Services_Ref/qsref_main/function_group_10.html>

    Reinder
    Reinder Guest

  6. #6

    Default Re: Restricting Mouse Movement...possible?


    Thanks to all for your thoughts. Some of those suggested calls look
    like exactly what I need...especially if I can use them in a straight C
    carbon application allowing it to be used in OS9 and OSX? A quick look
    seems to indicate that quartz is available to carbon, and, if so, I
    always thought if something is "carbonized", it can be used with OS9
    and OSX. So there's hope???? (but I've yet to try any of the
    suggestions. Hope springs eternal!)


    In article <wxs.nl>, Reinder
    Verlinde <invalid> wrote:
     
    Bill Guest

  7. #7

    Default Re: Restricting Mouse Movement...possible?

    On Thu, 6 May 2004, Bill wrote:
     

    There are two different meanings to "Carbon". One is the C API available
    on OS X. One is the C API that you can link against and produce a binary
    that runs on both 9 and X. The two are similar, but there are quite a few
    OS X-only Carbon APIs. Finally, the CoreGraphics stuff isn't part of
    Carbon at all, so it'll only work on OS X. If you need to write a program
    that'll work on both platforms, you'll have to use a different technique
    on each one.
    Michael Guest

  8. #8

    Default Re: Restricting Mouse Movement...possible?


    Thanks Michael. You're right, the two aspects of Carbon are obviously
    confusing.

    Were I to support OSX only, but still want to write to the Carbon C
    API, are you saying I can or can't use the CoreGraphics stuff?

    I'm not sure if you mean I can't use CoreGraphics stuff at all if I
    write to the Carbon C API AND have intentions of using on OS9, or if
    you mean CoreGraphics is only available to Cocoa (as opposed to Carbon)
    and even if I intend my application to only run on OSX, if I write to
    the Carbon C API I still can't use CoreGraphics?

    In article <twistedsys.net>, Michael
    Ash <com> wrote:
     
    >
    > There are two different meanings to "Carbon". One is the C API available
    > on OS X. One is the C API that you can link against and produce a binary
    > that runs on both 9 and X. The two are similar, but there are quite a few
    > OS X-only Carbon APIs. Finally, the CoreGraphics stuff isn't part of
    > Carbon at all, so it'll only work on OS X. If you need to write a program
    > that'll work on both platforms, you'll have to use a different technique
    > on each one.[/ref]
    Bill Guest

  9. #9

    Default Re: Restricting Mouse Movement...possible?

    In article <070520040851599325%com>, com
    says... 

    The Core* APIs are OS X only and are seperate from Carbon and Cocoa but
    you can mix and match your APIs. So, if you are targetting OS X then
    using Carbon and CoreGraphics is fine. If you are targetting OS 9 with
    Carbon then you cannot use CoreGraphics and you must restrict yourself
    to the subset of Carbon that OS 9 supports.
    James Guest

  10. #10

    Default Re: Restricting Mouse Movement...possible?


    "James Weatherley" <net> wrote in message
    news:Individual.NET... 
    >
    > The Core* APIs are OS X only and are seperate from Carbon and Cocoa but
    > you can mix and match your APIs. So, if you are targetting OS X then
    > using Carbon and CoreGraphics is fine. If you are targetting OS 9 with
    > Carbon then you cannot use CoreGraphics and you must restrict yourself
    > to the subset of Carbon that OS 9 supports.[/ref]


    But you generally can include a header, weak link the appropriate stub
    library, and then make sure the OSX function is never called on OS9 and/or
    if missing. I've done that successfully w/ LaunchServices (which is OSX
    only) by checking the environment before calling it and using a different
    method if it's OS9. That gives you common source with an if/else to select
    the right path.

    You could just check to see if the function is defined, which lets you use
    the X version if it's ever added to Carbon. That's pretty unlikely, though,
    and I prefer to control exactly what I call. The Help API, for example,
    contains some supposedly supported functions that fail silently on OS 9 and
    require workarounds/alternate methods that can't be triggered by an error
    return.

    Paul


    Paul Guest

  11. #11

    Default Re: Restricting Mouse Movement...possible?

    In article <050520041145561941%com>,
    Bill <com> wrote:
     

    I think you're going about this the wrong way. There is some function
    to enter full screen mode (used to be part of QuickTime). That should
    get rid of most of your problems.

    Apart from that, Carbon Events include a mouse delta with mouseMoved
    events, which you could use to detect the user's mouse movements,
    because AFAIK it was added exactly for the use you have, and is set
    correctly even if the mouse pointer "bumped into the corner of the
    screen".

    Not sure whether the latter ever made it into CarbonLib, though, so you
    might have to do that weird thing you suggested on OS 9 using one of the
    old LM functions or whatever it was (haven't done Classic programming
    in years).

    HTH,
    -- Uli
    http://www.zathras.de
    Uli Guest

  12. #12

    Default Re: Restricting Mouse Movement...possible?

    In article <070520040851599325%com>,
    Bill <com> wrote:
     

    Which is why usually they're told apart by talking of CarbonLib (CFM)
    and Carbon (MachO). Carbon (MachO) is only available on OS X.
     

    You can, but only while running under OS X. Also, since your app has to
    be a CFM app, but CarbonLib (CFM) includes neither the MacOS X-specific
    APIs, nor does it include CoreGraphics, you'll have to use
    CFBundleFunctionPointerForNameThisNameIsWayTooLong () to load a pointer
    to CG functions at runtime to call.

    And no, Cocoa doesn't even enter the picture. Pity.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

  13. #13

    Default Re: Restricting Mouse Movement...possible?

    In article <Individual.NET>,
    James Weatherley <net> wrote:
     

    I don't think they are *all* separate? I distinctly remember that
    CFString and a few other tiny parts of CoreFoundation (CFBundle, I
    think) were backported to OS 9 for CarbonLib. Not that this helps,
    because I doubt that would include much of CoreGraphics that is relevant
    to this discussion, but...
     

    Or, as others mentioned, the OP needs to write code that uses different
    APIs depending on the system version they're running under, by messing
    with CFBundle.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

Similar Threads

  1. Mouse look + WADS movement
    By Colin James in forum Macromedia Director 3D
    Replies: 0
    Last Post: November 3rd, 08:54 PM
  2. inverting the mouse movement
    By mygraneboy webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 7
    Last Post: October 13th, 07:24 PM
  3. tracking mouse movement..
    By gops in forum Mac Programming
    Replies: 0
    Last Post: September 18th, 05:12 AM
  4. recording mouse movement...
    By Karl Sigiscar in forum Macromedia Director 3D
    Replies: 0
    Last Post: August 19th, 05:10 PM
  5. detecting Mouse movement
    By Mike Soriano in forum Macromedia Director Lingo
    Replies: 4
    Last Post: July 10th, 06:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139