Weirdly I got asked this in the pub last week. The answer I gave then was quite extensive, and s basically self-hypnosis. But there is an easier one.
When you feel your attention slipping, and assuming you are at a desk rather than performing oral sex, you should
1. Look at your desk
2. Fix in your mind an image of where everything is on the desk
3. Gently close your eyes, keeping the image
4. Put out your hand, and touch an object
5. You will find your hand instantly connects
6. Now grasp and move that object
7. Repeat the proces for different objects
8. Return to objects you have already moved
9 Keep your eyes closed throughout
When you get bored, open your eyes. You will feel incredibly calm and focussed. It's a technique I invented for getting through exams.