Guys (and gals), you’re mixing a LOT of different issues here.
First off, let’s set aside the Mac’s. Fine machines, but not what the OP’s talking about.
As others have sort of said indirectly, there are two different pieces of info that are generated when a key is pressed.
The keyboard itself transmits a code, called the scan code, which defines which physical button was pushed, and each shift key, alt key, control key, number key, etc., has a different scan code. At that level, the 4 above the ER keys and the 4 on the numeric pad are two utterly unrelated buttons. Likewise left shift and right shift are two different and unrelated buttons.
That scan code gets sent to some programming built into the PC called the keyboard BIOS. The BIOS diddles with it and sends it along to the OS, in this case Windows.
Windows in turn converts the scan code into a character code. At that point, the two 4 keys become indistinguishable, LeftShift and “a” together become “A”, and that’s also where non-US keyboard characters get mapped. For example, on German keyboards, something like LeftCtrl+e = e with unlaut.
A Windows program can just accept the pre-digested characters. That’s the norm with your browser, Word, etc. About 99% of the programs the typical user encounters work this way.
But, if the program wants to, it can dig into the scan codes so it can tell which 4 was pressed. As others have said, normally it’s games and CAD and other special purpose programs that do that. Restaurants, where PCs serve as combo cash registers & ordertaking stations, often have weirdball keyboards with 1 dedicated button for each menu item. This is another example of a place where accessing the scan codes makes sense. Those weirdball keyboards do NOT behave like typical PC QWERTY boards and have very different scan code sets.
As well, a program can dig a little deeper and react to the key being pressed, and react again to the key being released. Those are two different actions. A typical Windows program reacts to the key press and ignores the key release.
It’s kind of fun to alter that behavior and make programs react to key release instead. If you type while looking at the screen, you’ll be utterly crippled. Funny how something so small makes such a huge difference in human perception of the task.
Last of all, turning to the ALT + numeric pad mystery.
As part of the Keyboard BIOS spec of the original PC, a feature was added for creating any character code, even those for which there wasn’t a button on the keyboard.
That feature is implemented by pressing either alt key and typing the 3 digit code from 000 to 255 on the numeric pad. The keyboard BIOS would interpret that specific “chord” a special way and provide the appropriate character code.
Pressing an alt key and typing 3 digits on the keys above the alphabet does NOT trigger that feature and instead transmits the codes for, say, Alt-1, Alt-4, and Alt-5 in turn.
A few years ago, the BIOS standard was updated as part of the ongoing internationalization of the PC and the advent of Unicode to supplant ASCII. Now, character codes aren’t 8 bits = 1 byte = 256 possibilities, but rather 16 bits = 2 bytes = 65536 possibilities (slight simplification here).
And the keyboard BIOS now processes Alt+4 digits on the numeric pad as a single Unicode character. That still only covers some 9999 codes,. but it’s alot more than the old 256.
And that’s why pressing Alt and 0-1-5-1 on the numeric pad produces an em dash. You can press Alt + 0065 and get an “A”. At the character code level, that “A” is indistinguishable from the conventional shift+“a” “A”. But dig deeper and there’s a lot of difference.
There’s a whale of a lot more going on inside a PC keyboard than there was on a manual or even electric typewriter.
Seque back to Macs: All the same sorts of things are happening in a Mac keyboard too. The terminology is different, the code values are different, but the idea is the same. A string of button presses and releases is translated through multiple levels of software to some set of codes that can be interpretted as letters and numbers and symbols.