I don't think you can solve this issue.
If it was vCoH it will be solvable but not for CoH 2.
Application like AutoHotkey have no way to know the unit selected so you can't choose a case where you want y key and x key switched and a case where y key and x key stay unchanged.