"For I have kept the ways of the Lord, and have not wickedly departed from my God." Psalm 18:21
So what is this key? How do we keep from departing from the Lord? How do we continue to stay close to Him? By "keeping the ways of the Lord". His "ways" literally means- to go in His direction and follow His path. We do this through keeping His commandments and submitting to His will.
You can't obey and disobey the Lord's commandments at the same time. You can't keep His ways and your own ways at the same time. You can't follow His will and your own will both at once. His will will always take you in a different direction than the will of your own flesh. So you will either have to go in one direction or the other. Physically speaking, I can't go to the left and right at the same time. When I get in my car and start driving, I can't go north and south at the same time. I either have to drive in the direction of north or south, but not both. It's the same in dealing with our spiritual life. We can't do both- we can't go in God's direction and our own at the same time.
If you feel yourself getting further away from the Lord it is because you are not keeping His ways- you are going in another direction and that direction, since it is not His direction, is leading you away from Him. The solution is to repent, turn around, then start following His direction. You will find that when you do, you will be getting closer to Him and off the road of departure from Him.
Have a great day. Following the Lord's direction will keep us from departing from Him.
For further reading:
Proverbs 4:4; 3:1; 7:2; 5:7