Add a Keyframe Option to a Button in a Panel
Window manager properties are not animatable

Doh.. should have looked harder. The issue here is the use of window manager

&gt;&gt;&gt; C.window_manager.keyframe_insert('test')
Traceback (most recent call last):
  File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
TypeError: bpy_struct.keyframe_insert() property "test" not animatable


Use another ID type, Scene for example and all is sweet.



import bpy
from bpy.props import BoolProperty


def update_test(self, context):

    test = int(self.test)
    return


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):

        scene = context.scene
        layout = self.layout
        layout.use_property_split = True
        layout.use_property_decorate = True
        obj = context.object

        col = layout.column()
        col.prop(obj, "location")
        row = self.layout.row()
        sub = row.row()
        label = "test = 1" if scene.test else "test = 0"

        sub.prop(scene, 'test', text=label, toggle=True)

        return
        icon = 'DECORATE_KEYFRAME' if wm.test else 'DECORATE'
        sub.operator("object.simple_operator", text="", emboss=False, icon=icon)


def register():
    bpy.types.Scene.test = BoolProperty()
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()


Notice can emulate this with an operator. Have put in the draw method to display only icon for operator (example toggles icon simply using bool value)  Otherwise could pass the path to operator and keyframe insert, change icon based on key at that frame.