How to set parameters on objects position while animating?
Don't try to animate every single part by itself, this would lead to the need of lots of adjustments (so-called "counter-animation"), wich should always be avoided.

Instead, you have to build a correct hierarchy over your spare parts, something like set the rifle butt parent of trigger, sight, stack, .... 

Then you start animating the butt with the "big" movements, then animate the trigger relatively to the butt .... 

In a professional environment you would build an armature, parent each part of the gun to a bone, you would have all bones child of a Master bone, you could have some automatized or pre-recorded sets of movements .... 

Lot of things to learn... Enjoy!