Mac is typing wrong things with external keyboard

I have found the problem, the Input Source in System Preferences was set to ABC. I saw the keyboard outline and realized it was different from my external keyboard. I changed it to a suitable one and it worked.

I found this thanks to Tom Gewecke’s comment.