MAXScript Tools and Interaction with 3ds Max > Interacting with the 3ds Max User Interface > MouseTrack >

# mouseTrack() Function

The mouseTrack function lets you register a MAXScript function to track the mouse. While the tracking is going on, this function is called whenever a mouse action occurs, such as a button click or a drag, etc.

The function has the form:

    mouseTrack [on:<node>] [prompt:<message_string>] [snap:#2D|#3D] [trackCallback:fn|#(fn,arg)]

    on:<node>

Optionally specifies a scene object to track on. If you don't supply an object, the mouse tracks on the current active grid. Note that the object surface tracker uses the SDK function IntersectRay() which is not reliably implemented on all object types. Editable meshes always work OK, so you can convertToMesh() if needed.

    prompt:<message_string>

Displays the prompt message in the MAX status line

    snap:#2D|#3D

Relevant when not tracking on an object surface (no on :<node> specified). If snap mode is on and #2D is supplied, snaps to snap points on grid, if #3D is specified snaps to any near snap point in space.

    trackCallback:fn|#(fn,arg)

Is where you specify the function to be called as the mouse is dragged over the active grid or object surface. You can specify it is a single function or a function and an argument value in a two element array. The latter form is useful if you have a common callback function for many tasks and want to send in a parameter to control its operation for a particular use. The function you give must be of the following form:

    fn callback_fn msg ir obj faceNum shift ctrl alt = ...

in other words, a scripted function with 7 arguments. While the tracking is going on, it is called whenever a mouse action occurs, such as a button click or a drag, etc.

The 'msg' argument is a message code that indicates what kind of action occurred, and can be one of:

    #freeMove - means the mouse is moved without a button being pressed
    #mousePoint - means the left mouse button has just been pressed
    #mouseMove - means the mouse is being dragged with the left button down
    #mouseAbort - means the right mouse button was clicked, normally meaning cancel

    'ir'

The grid or surface intersection normal Ray at the current mouse position. The ray has a .pos property giving the point in space of the normal and a .dir property giving the normal's direction vector.

    'obj'

The object being dragged over or undefined if no on:<node> was supplied.

    'faceNum'

The number of the face the mouse is over if the object being tracked is an editable mesh, undefined otherwise.

    'shift', 'ctrl' and 'alt'

True or false depending on the down or up state of the Shift, Ctrl and Alt keys on the keyboard.

The function should return the special value #continue to continue tracking or any other value to halt tracking. That value then becomes the result of the original mouseTrack() call.

#### See Also

- Rollout User-Interface Controls