Reversing keyframes in the animation window

As the topic says. I select a bunch of keyframes, and I want to just right click and choose reverse keyframes like you would do in After Effects or other softwares. Is there some sort of additional animation tools this is a part of? has anyone done something in the asset story? I googled and i did the search on this forum and didn’t see any tools for this. And i don’t want the hack of clicking on the animation in the animator and setting speed to -1 or anything like that. I just want to reverse only my selected keyframes.

I’ve done keyframe manipulation through an editor script before. Here’s a few lines to help you get going:

[MenuItem("My Custom Stuff/Modify Animation Clips")] // you could add a shortcut here, see MenuItem docs
public static void ModifyAnimationClip()
{
    if (!EditorWindow.HasOpenInstances<AnimationWindow>())
        return;

    var window = EditorWindow.GetWindow<AnimationWindow>();
    var originalClip = window.animationClip;

    // this operates non-destructively to create a copy of the clip
    // which is important at least up until you're 100% confident
    // you're not destroying your real clips
    var copy = Object.Instantiate(originalClip);
    var bindings = AnimationUtility.GetCurveBindings(copy);

    foreach (var b in bindings)
        PrintKeys(b, AnimationUtility.GetEditorCurve(copy, b).keys);

    foreach (var b in bindings)
    {
        AnimationCurve curve = AnimationUtility.GetEditorCurve(copy, b);

        // keys filter within the selected range
        // I'm not sure the API for that

        AnimationUtility.SetEditorCurve(copy, b, curve);
    }

    var path = AssetDatabase.GenerateUniqueAssetPath(AssetDatabase.GetAssetPath(originalClip));
    AssetDatabase.CreateAsset(copy, path);
    Debug.LogWarning($"Created clip copy at {path}", copy);
}

static void PrintKeys(EditorCurveBinding b, Keyframe[] keys)
{
    var curveStr = string.Join("\n", keys.Select(k => $"@{k.time} = {k.value}   |  in = {k.inTangent}, {k.inWeight} | " +
                                    $"out = {k.outTangent}, {k.outWeight}"));
    Debug.Log($"{b.path}/{b.propertyName} | {b.type}" +
        $"\nKeys={keys.Length} ->\n{curveStr}");
}

The “reverse” procedure might be a bit tricky because every curve / tangent might need care in reversing. And you need to decide how this applies to types that aren’t float/Vector3. A bool flip? It depends… so a warning: this is several steps above beginner level.*

* for the general case. If you’re just reversing a sprite animation clip then probably it’s not so bad