How to exchange two keys on the keyboard (El Capitan) I am currently using a German keyboard on El Capitan. I want to change the keymap for y and z. I have searched relevant information on Google, but the information which I have found so far is so old that I could not apply them.

I also tried to use the following .Xmodmap: 

keycode  52 = z Z z Z leftarrow yen leftarrow
keycode  29 = y Y y Y guillemotright U203A guillemotright


But this does not work.
Use the (free) program Ukelele.


Create a new keyboard layout based on your current one (File -> New From Current Source).
On the graphical interface click on the key to which you want to assign a different value, then  provide the intended output:


Save the new layout as a .keylayout file to /Library/Keyboard Layouts*.

Log off, log on.
Open System Preferences and select the new layout in Input Sources -> + -> Others -> your_layout_name.




* You can also save the file in your user's Library folder instead of the system one, but then if you lock the machine (i.e. switch to the lock screen), the keyboard layout might change at each unlock.