Retrieving selected keyframes


I’m trying to get a list of all the selected keyframes in an f-curve:

obj = bpy.context.active_object;

fcurves = obj.animation_data.action.fcurves;

curve = fcurves[0];

keyframes = curve.keyframe_points;

So, say I want to get all selected keyframes from the first f-curve. Is there a way to extract this information from its “keyframe_points” property, or am I going about it the wrong way?

Thank you.

This at the end of your code should work:

klist = [p for p in keyframes if p.select_control_point]

Perfect! And it works with both the DopeSheet and the Graph Editor.

This is exactly what I was looking for, thank you!