## FCurve.GetKeyIndex

### Introduced

v3.0

### Description

Returns the key index for the key at the specified frame. If the key does not exist the method returns -1.

### C# Syntax

    Int32 FCurve.GetKeyIndex( Object in_Frame, Double in_Tolerance );

### Scripting Syntax

    oLong = FCurve.GetKeyIndex( Frame, [Tolerance] );

### Return Value

Long

### Parameters

Parameter | Type | Description
--- | --- | ---
Frame | Variant | The key time in frames at which to look for the key.
Tolerance | Double | Key tolerance. Default Value: -1
Possible Values: | Description:
>0 | Matches key between Frame - Tolerance and Frame + Tolerance
0 | Key must be exactly at frame
-1 | Nearest 0.5 frame

### Examples

#### JScript Example

    /*

    	This JScript example illustrates how to use the resample method to

    	add keys to an fcurve and the getkeyindex() method to look up an

    	keys index from a frame value.

    */

    // Create a null

    Application.NewScene( null, false );

    var nullobj = ActiveSceneRoot.AddNull();

    // Create an fcurve on the posx parameter from the null

    var fc = nullobj.posx.AddFCurve()

    // Start editing the fcurve

    fc.BeginEdit();

    // Use the Resample method to add keys to the fcurve on every second frame

    var empty;

    fc.Resample(empty,empty,2);

    // Look up the key near frame 25

    var key, index, frame, tolerance, keyframe;

    frame = 24;

    tolerance = 1;

    if ( fc.KeyExists( frame, tolerance ) )

    {

    	// Get index from frame using a tolerance of 1 frame (for example, 25 +/- 1 frame).

    	// This will find the key at frame 23

    	index = fc.GetKeyIndex( frame, tolerance );

    	keyframe = fc.GetKeyFrame( index );

    	LogMessage( "found key " + index + " at frame " + keyframe + " between frame "

    		+ (frame-tolerance) + " and " + (frame+tolerance)  );

    	// Get the key at index

    	key = fc.GetKeyAtIndex( index );

    	// Set the key value

    	key.Value = Math.random() * 100;

    }

    // End editing the fcurve and put the undo event onto

    // the undo/redo stack

    fc.EndEdit();

    // Outputs:

    //INFO : found key 11 at frame 23.000000000000003 between frame 23 and 25

### See Also

FCurveKey.Index FCurve.Keys FCurve.GetKey FCurve.GetKeyFrame FCurve.GetKeyValue