Most operating systems (if not all) asks about the keyboard layout during installation. Why do they need to know the layout? I mean, when pressing key, does the keyboard send a specific signal indicating what it represents (if so, why needing to specify the layout?) or it sends a signal indicating its position (the second raw, third key) and then the OS detects what key is that from the layout specified?
keyboards "send" numeric scancodes.
The operating system has to convert the scancode into an action or a displayable character.
For example, Shift+3 is the same scancodes on UK and US keyboards but needs to result in differing characters.
The latter. Each key on a keyboard simply sends a number back to the system, which the OS then interprets into a given key using Keyboard sets.
For example, if i hit a given key it could send "26" to the operating system. the OS then would look up what "26" means in the US keyboard layout and comes back with "3" which it then sends to the given text field.
As mentioned by the others, the keyboards just send scans codes and it's up to the OS to determine what they mean. Realize also that not every keyboard layout has readily available proprietary hardware, so many people end up using a physical keyboard that is close to their locale but then remap the keys to their specific layout.
For example, I type on the US-Dvorak layout. Hardwired Dvorak keyboards are rare and very expensive, so when I install Windows I just switch it to the US-Dvorak layout and then rearrange my keycaps or add stickers (or just touch type).