Know yourself and your own mind well enough to be able to distinguish your own thoughts from the thoughts Shaytaan whispers into your brain, and the impulses of your nafs that itch at you.
Shaytaan is impatient, he will bombard you with a variety of notions; if you do not respond to one, he will try another. When your mind becomes confused and can’t focus because you find it going in many directions at once; know this is from Shaytaan.
If you keep having the same persistent urge, usually something that is demanding gratification of some kind, but which has no real practical benefit other than gratification; know this is likely your nafs.
If you can learn to identify these two types of mental disruption, you can train yourself to overcome them.