Right mouse button is either contextual automatic action when no command is selected, or cancel when a command is selected.
Left mouse button is select unit when no command is selected, or confirm target when a command is selected.
So e.g., with Fire (F):
No command selected, select unit, Right click on enemy unit =
Fire at that unit
Select unit, select Fire, Left click on enemy unit =
Fire at that unit
Select unit, select Fire, Right click anywhere =
Cancel the Fire command selection.
No command selected, no unit selected, left click on enemy unit =
Select that unit (nothing happens, it's an enemy).