If the issue ends up being you clicking outside of the TF2 window the solution is to halve (or whatever factor you want) your mouse DPI and double your ingame sens.
Here is another solution if you can't or don't want to mess with your mouse DPI:
http://www.snakebytestudios.com/projects/apps/cursor-lock/