You should give use more information about your external keyboard mapping. Your are only talking about 2 specific keys. That special keys can have different location with respect to your keyboard layout (and brand).
I would say that you have an AZERTY based mapping but where ² and < are inverted :
Solution on macOS 10.12
The best way is:
- go in System preferences > keyboard.
- click Input Sources tab (4th tab on macOS if you're OS is not in English).
- then click on the "+" button at the bottom left of the window for adding a new layout.
- browse the AZERTY mapping and try to find which one corresponds to yours.
- tick "Show input in the menu bar" (bottom of the window, first option), it let you see you current mapping in your OS menu bar. You should see appear here a country flag or "ABC" or "ABC - AZERTY" or something else depending of your chosen layouts.
If your external keyboard has an unusual mapping, you have to try manually several kinds of layouts (ex: french/canadian french/swiss french).
- Select the new added layout in the menu bar,
- open a text editor to try if your software mapping corresponds to your physical mapping.
- You should find the good one easily after few attempts.
If you can't find it
- A straightforward solution (if physical keys are similar) is to swap them physically.
- There is a way to write your own mapping configuration file on an Unix system, but we can talk about that only if nothing goes right.
Trick
An easy way for switching your layout whether you are using your laptop or ext. keyboard is to add a shortcut for making the switch:
- go in System preferences > keyboard.
- click "Shortcuts" tab (3rd tab).
- select "Input Sources" in the left panel.
- then add your special shortcut.