You could remap the mouse buttons using AutoHotkey. As far as the ability to specify in the script that the remapping only occur in certain circumstances, I'm not familiar with Fences, but you have a lot of flexibility with AutoHotkey. If you're not familiar with it, just Google it and you find a ton of information. It's free by the way.