We don't always know when the devil is directly tempting us, and when he is only working in the background. In reality, however, it doesn't make any difference, because the result is the same: We are being tempted to turn our backs on God and do wrong.
Ultimately, of course, the devil is the source of all temptation (which is why the Bible calls him "The tempter"–Matthew 4:3). At the same time, he is able to succeed only because we let him succeed–and we let him succeed because of our own inner weaknesses. The Bible says, "each one is tempted when, by his own evil desire, he is dragged away and enticed" (James 1:14).
This is one reason why we need Christ. Only He can forgive us when we sin, and only He can give us the strength by His Holy Spirit to resist temptation. We don't have the strength in ourselves to live the way we should, and when we try to fight the devil on our own, we will fail. But Christ is stronger than Satan, and the Bible reminds us that "The reason the Son of God appeared was to destroy the devil's work" (1 John 3:8).
I have a friend who says, "When the devil comes knocking, I just send Jesus to the door." Does Jesus live in your heart? Make sure of your commitment to Him, and then when temptations come (and they will), ask Him to give you the strength to overcome them. The Bible promises, "Resist the devil, and he will flee from you" (James 4:7).