Swap CMD and Alt only on external keyboard
On my external mechanical keyboard the Super/Windows/CMD key is between Ctrl and Alt, but on the Mac keyboard it's between Alt and Space.
Can I swap CMD and Alt only on the external keyboard?
Solution 1:
There is a section dedicated to this under → System Preferences → Keyboard:
Open Modifier Keys… and reassign them from here:
These settings are specific to each external keyboard you have connected. They will “stick” between reboots, as well as whenever you unplug an external keyboard and plug back it in.
Solution 2:
The built-in macOS solution did not work for me because there's no option to select a different keyboard.
For macOS Sierra to Mojave (current release as of right now), Karabiner-Elements does exactly this. You can find the GitHub page at https://github.com/tekezo/Karabiner-Elements.
It runs in the background. In the preferences, you configure the target device for modification and it remembers the settings. I have a bluetooth keyboard (Logitech G613) where only that keyboard's CMD and ALT are swapped. I use this keyboard between my PC and Mac.
Below you see an example of Karabiner-Elements v12. It doesn't show my G613 because it is not connected right now.
Solution 3:
I use Karabiner for my external KB, I think it's the only utility currently available but Google is your friend. As to the second question - so far as I know, only if you can figure out a way to run Karabiner when the external KB is attached but not otherwise. HTH.