If they're like fruit flies, they are attracted to the fermentation. Like buying a scratching post for cats to get them to stop scratching the furniture, you have to give the bugs something more attractive.
I use red wine vinegar with a few drops of dish soap. Give it a mix and leave it near your fermentor. It's much funkier than the fermenting beer and they'll be attracted to that. The soap breaks the surface tension on the vinegar and the little bastards drown.