You can send Keybind A, for one role
And Keybind B, for another.

Have the mapped key, that sends a keystroke action for Keybind A.
And then irregardless of that being Spec 1 or Spec 2, have the correct macro on that keybind for each toon.
Long term, having DPS being Spec 1 and Tank or Healing as Spec 2 might be a better idea.

But nothing says you cannot have Keybind A = DPS.
Which on toon one is a macro, switching to Spec 1 and on another toon is a similar macro, but which switches that toon to Spec 2.