Why do Macs ask you to press random keys when connecting a new keyboard

Why do Macs ask you to press random keys when connecting a new keyboard? – Unsung by Marcin Wichary

So, pressing the thing next to the left Shift can help Apple understand whether the keyboard is American or Japanese (always Z) or European (something else, but never Z). And pressing the thing next to the right Shift differentiates JIS (where it’s the _ key) from another keyboard (always /).

I did this recently as part of setting up my Nuphy Air 75s.

UPDATED