Stop animation while playing?

Is it possible to make an input stop/pause an animation while playing?
Can it be done with a script?

Example:

Animation is playing
When SPACE is pressed it will stop.

Thank you

Alt+A is the default hotkey. Change it to the space bar.

No I mean in-game.

If you want to do this in LogicBriks, then you can use an action actuator in loop stop mode which is controlled by an toggle property. If you activate continue the action will start at the frame where it was stopped last time. If it is deactivated the action will start at the start frame.
If you want to have more control, then you can use a property (float) which is counting up every frame as long the space bar is not pressed. This property can be used with an action actuator in property mode.

If you want to do it with Python you can use playAction() and stopAction().
https://www.blender.org/api/blender_python_api_2_77_1/bge.types.KX_GameObject.html?highlight=playaction#bge.types.KX_GameObject.playAction

ActionStartStop.blend (88 KB)

Thanks alot!